Skip to content

Commit

Permalink
reformat codes. this commit only changes coding style.
Browse files Browse the repository at this point in the history
  • Loading branch information
chobie committed Apr 3, 2013
1 parent 30d313c commit 47f471e
Show file tree
Hide file tree
Showing 18 changed files with 179 additions and 162 deletions.
22 changes: 11 additions & 11 deletions src/Fluent/Autoloader.php
Expand Up @@ -3,13 +3,13 @@
* Fluent-Logger-PHP
*
* Copyright (C) 2011 - 2012 Fluent-Logger-PHP Contributors
*
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Expand All @@ -22,7 +22,7 @@ class Autoloader
{
const NAME_SPACE = 'Fluent';
protected static $base_dir;

/**
* register Fluent basic autoloader
*
Expand All @@ -34,7 +34,7 @@ public static function register($dirname = __DIR__)
self::$base_dir = $dirname;
spl_autoload_register(array(__CLASS__, "autoload"));
}

/**
* unregister Fluent basic autoloader
*
Expand All @@ -44,7 +44,7 @@ public static function unregister()
{
spl_autoload_unregister(array(__CLASS__, "autoload"));
}

/**
* autoload basic implementation
*
Expand All @@ -54,17 +54,17 @@ public static function unregister()
public static function autoload($name)
{
$retval = false;
if (strpos($name,self::NAME_SPACE) === 0) {
$parts = explode("\\",$name);
if (strpos($name, self::NAME_SPACE) === 0) {
$parts = explode("\\", $name);
array_shift($parts);
$expected_path = join(DIRECTORY_SEPARATOR,array(self::$base_dir, join(DIRECTORY_SEPARATOR,$parts) . ".php"));

$expected_path = join(DIRECTORY_SEPARATOR, array(self::$base_dir, join(DIRECTORY_SEPARATOR, $parts) . ".php"));
if (is_file($expected_path) && is_readable($expected_path)) {
require $expected_path;
$retval = true;
}
}

return $retval;
}
}
5 changes: 3 additions & 2 deletions src/Fluent/Logger/BaseLogger.php
Expand Up @@ -28,7 +28,7 @@ abstract class BaseLogger implements \Fluent\Logger\LoggerInterface
protected $error_handler = null;

/**
* @param $entity
* @param $entity
* @param void $error error message
*/
public function defaultErrorHandler(BaseLogger $logger, Entity $entity, $error)
Expand All @@ -38,7 +38,7 @@ public function defaultErrorHandler(BaseLogger $logger, Entity $entity, $error)

/**
* @param Entity $entity
* @param void $error error message
* @param void $error error message
*/
protected function processError(Entity $entity, $error)
{
Expand All @@ -61,6 +61,7 @@ public function registerErrorHandler($callable)
} else {
throw new \InvalidArgumentException("Error handler must be callable.");
}

return true;
}
}
6 changes: 3 additions & 3 deletions src/Fluent/Logger/ChainLogger.php
Expand Up @@ -26,7 +26,7 @@
*/
class ChainLogger extends BaseLogger
{
protected $chain = array();
protected $chain = array();
protected $errors = array();

public function __construct()
Expand All @@ -35,7 +35,7 @@ public function __construct()

public function addLogger(\Fluent\Logger\BaseLogger $logger)
{
$logger->registerErrorHandler(array($this,"defaultErrorHandler"));
$logger->registerErrorHandler(array($this, "defaultErrorHandler"));

$this->chain[] = $logger;
}
Expand All @@ -47,7 +47,7 @@ public function defaultErrorHandler(BaseLogger $logger, Entity $entity, $error)

/**
* @param string $tag
* @param array $data
* @param array $data
*
* @api
*/
Expand Down
15 changes: 9 additions & 6 deletions src/Fluent/Logger/ConsoleLogger.php
Expand Up @@ -28,7 +28,7 @@ class ConsoleLogger extends BaseLogger
{
/* @var resource handle */
protected $handle;

/**
* create Console logger object.
*
Expand All @@ -37,7 +37,7 @@ class ConsoleLogger extends BaseLogger
public function __construct($stream = null)
{
if (is_null($stream)) {
$stream = fopen("php://stderr","w");;
$stream = fopen("php://stderr", "w");
}
$this->handle = $stream;
}
Expand All @@ -50,18 +50,20 @@ public function __construct($stream = null)
public static function open()
{
$logger = new self();

return $logger;
}

/**
* send a message to specified fluentd.
*
* @param string $tag
* @param array $data
* @param array $data
*/
public function post($tag ,array $data)
public function post($tag, array $data)
{
$entity = new Entity($tag,$data);
$entity = new Entity($tag, $data);

return $this->postImpl($entity);
}

Expand All @@ -85,8 +87,9 @@ protected function postImpl(Entity $entity)
* 2012-02-26T01:26:20+0900 debug.test {"hello":"world"}
*/
$format = "%s\t%s\t%s\n";

return $this->write(sprintf($format,
date(\DateTime::ISO8601,$entity->getTime()),
date(\DateTime::ISO8601, $entity->getTime()),
$entity->getTag(),
json_encode($entity->getData())
));
Expand Down
6 changes: 3 additions & 3 deletions src/Fluent/Logger/Entity.php
Expand Up @@ -32,8 +32,8 @@ class Entity
/**
* create a entity for sending to fluentd server
*
* @param $tag
* @param $data
* @param $tag
* @param $data
* @param int $time unixtime
*/
public function __construct($tag, $data, $time = null)
Expand All @@ -48,7 +48,7 @@ public function __construct($tag, $data, $time = null)
$this->time = time();
}

$this->tag = $tag;
$this->tag = $tag;
$this->data = $data;
}

Expand Down
8 changes: 4 additions & 4 deletions src/Fluent/Logger/Exception.php
Expand Up @@ -23,10 +23,10 @@ class Exception extends \Exception
protected $entity;

/**
* @param $tag
* @param $data
* @param string $message
* @param int $code
* @param $tag
* @param $data
* @param string $message
* @param int $code
* @param \Exception|null $previous
*/
public function __construct(Entity $entity, $message = "", $code = 0, \Exception $previous = null)
Expand Down
23 changes: 13 additions & 10 deletions src/Fluent/Logger/FileLogger.php
Expand Up @@ -58,18 +58,20 @@ public function __construct($path)
public static function open($path)
{
$logger = new self($path);

return $logger;
}

/**
* write a message to specified path.
*
* @param string $tag
* @param array $data
* @param array $data
*/
public function post($tag,array $data)
public function post($tag, array $data)
{
$entity = new Entity($tag, $data);

return $this->postImpl($entity);
}

Expand All @@ -86,21 +88,20 @@ public function post2(Entity $entity)
protected function postImpl(Entity $entity)
{
$packed = json_encode($entity->getData());
$data = $wbuffer = sprintf("%s\t%s\t%s\n",
date(\DateTime::ISO8601,
$entity->getTime()),
$entity->getTag(),
$packed . PHP_EOL
$data = $wbuffer = sprintf("%s\t%s\t%s\n",
date(\DateTime::ISO8601, $entity->getTime()),
$entity->getTag(),
$packed . PHP_EOL
);

$length = strlen($data);
$length = strlen($data);
$written = 0;

try {
if (!flock($this->fp, LOCK_EX)) {
throw new \Exception('could not obtain LOCK_EX');
}
fseek($this->fp,-1, SEEK_END);
fseek($this->fp, -1, SEEK_END);

while ($written < $length) {
$nwrite = fwrite($this->fp, $wbuffer);
Expand All @@ -115,14 +116,16 @@ protected function postImpl(Entity $entity)
$retry++;
}
$written += $nwrite;
$wbuffer = substr($wbuffer,$written);
$wbuffer = substr($wbuffer, $written);
}

flock($this->fp, LOCK_UN);
} catch (\Exception $e) {
$this->processError($this, $entity, $e->getMessage());

return false;
}

return true;
}

Expand Down

0 comments on commit 47f471e

Please sign in to comment.