1
0
mirror of https://github.com/Seldaek/monolog.git synced 2025-08-06 13:16:39 +02:00
This commit is contained in:
Jordi Boggiano
2012-06-14 15:46:17 +02:00
parent 1530322897
commit da33c84d07
46 changed files with 193 additions and 206 deletions

View File

@@ -24,7 +24,7 @@ interface FormatterInterface
* @param array $record A record to format * @param array $record A record to format
* @return mixed The formatted record * @return mixed The formatted record
*/ */
function format(array $record); public function format(array $record);
/** /**
* Formats a set of log records. * Formats a set of log records.
@@ -32,5 +32,5 @@ interface FormatterInterface
* @param array $records A set of records to format * @param array $records A set of records to format
* @return mixed The formatted set of records * @return mixed The formatted set of records
*/ */
function formatBatch(array $records); public function formatBatch(array $records);
} }

View File

@@ -11,8 +11,6 @@
namespace Monolog\Formatter; namespace Monolog\Formatter;
use Monolog\Logger;
/** /**
* Encodes whatever record data is passed to it as json * Encodes whatever record data is passed to it as json
* *

View File

@@ -11,8 +11,6 @@
namespace Monolog\Formatter; namespace Monolog\Formatter;
use Monolog\Logger;
/** /**
* Formats incoming records into a one-line string * Formats incoming records into a one-line string
* *

View File

@@ -11,8 +11,6 @@
namespace Monolog\Formatter; namespace Monolog\Formatter;
use Monolog\Logger;
/** /**
* Normalizes incoming records to remove objects/resources so it's easier to dump to various targets * Normalizes incoming records to remove objects/resources so it's easier to dump to various targets
* *

View File

@@ -87,6 +87,7 @@ abstract class AbstractHandler implements HandlerInterface
if (!$this->processors) { if (!$this->processors) {
throw new \LogicException('You tried to pop from an empty processor stack.'); throw new \LogicException('You tried to pop from an empty processor stack.');
} }
return array_shift($this->processors); return array_shift($this->processors);
} }

View File

@@ -11,10 +11,6 @@
namespace Monolog\Handler; namespace Monolog\Handler;
use Monolog\Logger;
use Monolog\Formatter\FormatterInterface;
use Monolog\Formatter\LineFormatter;
/** /**
* Base Handler class providing the Handler structure * Base Handler class providing the Handler structure
* *

View File

@@ -11,7 +11,6 @@
namespace Monolog\Handler; namespace Monolog\Handler;
use Monolog\Logger;
use Monolog\Formatter\ChromePHPFormatter; use Monolog\Formatter\ChromePHPFormatter;
/** /**
@@ -31,9 +30,9 @@ class ChromePHPHandler extends AbstractProcessingHandler
*/ */
const HEADER_NAME = 'X-ChromePhp-Data'; const HEADER_NAME = 'X-ChromePhp-Data';
static protected $initialized = false; protected static $initialized = false;
static protected $json = array( protected static $json = array(
'version' => self::VERSION, 'version' => self::VERSION,
'columns' => array('label', 'log', 'backtrace', 'type'), 'columns' => array('label', 'log', 'backtrace', 'type'),
'rows' => array(), 'rows' => array(),

View File

@@ -24,5 +24,5 @@ interface ActivationStrategyInterface
* @param array $record * @param array $record
* @return Boolean * @return Boolean
*/ */
function isHandlerActivated(array $record); public function isHandlerActivated(array $record);
} }

View File

@@ -11,7 +11,6 @@
namespace Monolog\Handler; namespace Monolog\Handler;
use Monolog\Logger;
use Monolog\Formatter\WildfireFormatter; use Monolog\Formatter\WildfireFormatter;
/** /**

View File

@@ -27,7 +27,7 @@ interface HandlerInterface
* *
* @return Boolean * @return Boolean
*/ */
function isHandling(array $record); public function isHandling(array $record);
/** /**
* Handles a record. * Handles a record.
@@ -38,40 +38,40 @@ interface HandlerInterface
* @return Boolean True means that this handler handled the record, and that bubbling is not permitted. * @return Boolean True means that this handler handled the record, and that bubbling is not permitted.
* False means the record was either not processed or that this handler allows bubbling. * False means the record was either not processed or that this handler allows bubbling.
*/ */
function handle(array $record); public function handle(array $record);
/** /**
* Handles a set of records at once. * Handles a set of records at once.
* *
* @param array $records The records to handle (an array of record arrays) * @param array $records The records to handle (an array of record arrays)
*/ */
function handleBatch(array $records); public function handleBatch(array $records);
/** /**
* Adds a processor in the stack. * Adds a processor in the stack.
* *
* @param callable $callback * @param callable $callback
*/ */
function pushProcessor($callback); public function pushProcessor($callback);
/** /**
* Removes the processor on top of the stack and returns it. * Removes the processor on top of the stack and returns it.
* *
* @return callable * @return callable
*/ */
function popProcessor(); public function popProcessor();
/** /**
* Sets the formatter. * Sets the formatter.
* *
* @param FormatterInterface $formatter * @param FormatterInterface $formatter
*/ */
function setFormatter(FormatterInterface $formatter); public function setFormatter(FormatterInterface $formatter);
/** /**
* Gets the formatter. * Gets the formatter.
* *
* @return FormatterInterface * @return FormatterInterface
*/ */
function getFormatter(); public function getFormatter();
} }

View File

@@ -120,6 +120,7 @@ class Logger
if (!$this->handlers) { if (!$this->handlers) {
throw new \LogicException('You tried to pop from an empty handler stack.'); throw new \LogicException('You tried to pop from an empty handler stack.');
} }
return array_shift($this->handlers); return array_shift($this->handlers);
} }
@@ -146,6 +147,7 @@ class Logger
if (!$this->processors) { if (!$this->processors) {
throw new \LogicException('You tried to pop from an empty processor stack.'); throw new \LogicException('You tried to pop from an empty processor stack.');
} }
return array_shift($this->processors); return array_shift($this->processors);
} }

View File

@@ -11,8 +11,6 @@
namespace Monolog\Formatter; namespace Monolog\Formatter;
use Monolog\Logger;
/** /**
* @covers Monolog\Formatter\LineFormatter * @covers Monolog\Formatter\LineFormatter
*/ */

View File

@@ -11,8 +11,6 @@
namespace Monolog\Formatter; namespace Monolog\Formatter;
use Monolog\Logger;
/** /**
* @covers Monolog\Formatter\NormalizerFormatter * @covers Monolog\Formatter\NormalizerFormatter
*/ */

View File

@@ -9,11 +9,11 @@
* file that was distributed with this source code. * file that was distributed with this source code.
*/ */
spl_autoload_register(function($class) spl_autoload_register(function($class) {
{
$file = __DIR__.'/../../../../src/'.strtr($class, '\\', '/').'.php'; $file = __DIR__.'/../../../../src/'.strtr($class, '\\', '/').'.php';
if (file_exists($file)) { if (file_exists($file)) {
require $file; require $file;
return true; return true;
} }
}); });

View File

@@ -38,6 +38,7 @@ class GelfHandlerTest extends TestCase
protected function getHandler($messagePublisher) protected function getHandler($messagePublisher)
{ {
$handler = new GelfHandler($messagePublisher); $handler = new GelfHandler($messagePublisher);
return $handler; return $handler;
} }

View File

@@ -16,11 +16,11 @@ use Gelf\Message;
class MockMessagePublisher extends MessagePublisher class MockMessagePublisher extends MessagePublisher
{ {
public function publish(Message $message) { public function publish(Message $message)
{
$this->lastMessage = $message; $this->lastMessage = $message;
} }
public $lastMessage = null; public $lastMessage = null;
} }

View File

@@ -48,7 +48,8 @@ class MongoDBHandlerTest extends TestCase
} }
if (!class_exists('Mongo')) { if (!class_exists('Mongo')) {
class Mongo { class Mongo
{
public function selectCollection() {} public function selectCollection() {}
} }
} }

View File

@@ -12,7 +12,6 @@
namespace Monolog\Handler; namespace Monolog\Handler;
use Monolog\TestCase; use Monolog\TestCase;
use Monolog\Logger;
/** /**
* @covers Monolog\Handler\RotatingFileHandler * @covers Monolog\Handler\RotatingFileHandler

View File

@@ -120,12 +120,12 @@ class SocketHandlerTest extends TestCase
{ {
$this->setMockHandler(array('fwrite')); $this->setMockHandler(array('fwrite'));
$callback = function($arg) $callback = function($arg) {
{
$map = array( $map = array(
'Hello world' => 6, 'Hello world' => 6,
'world' => false, 'world' => false,
); );
return $map[$arg]; return $map[$arg];
}; };
@@ -143,12 +143,12 @@ class SocketHandlerTest extends TestCase
{ {
$this->setMockHandler(array('fwrite', 'streamGetMetadata')); $this->setMockHandler(array('fwrite', 'streamGetMetadata'));
$callback = function($arg) $callback = function($arg) {
{
$map = array( $map = array(
'Hello world' => 6, 'Hello world' => 6,
'world' => 5, 'world' => 5,
); );
return $map[$arg]; return $map[$arg];
}; };
@@ -159,7 +159,6 @@ class SocketHandlerTest extends TestCase
->method('streamGetMetadata') ->method('streamGetMetadata')
->will($this->returnValue(array('timed_out' => true))); ->will($this->returnValue(array('timed_out' => true)));
$this->writeRecord('Hello world'); $this->writeRecord('Hello world');
} }
@@ -171,9 +170,9 @@ class SocketHandlerTest extends TestCase
$this->setMockHandler(array('fwrite', 'streamGetMetadata')); $this->setMockHandler(array('fwrite', 'streamGetMetadata'));
$res = $this->res; $res = $this->res;
$callback = function($string) use ($res) $callback = function($string) use ($res) {
{
fclose($res); fclose($res);
return strlen('Hello'); return strlen('Hello');
}; };
@@ -201,12 +200,12 @@ class SocketHandlerTest extends TestCase
{ {
$this->setMockHandler(array('fwrite')); $this->setMockHandler(array('fwrite'));
$callback = function($arg) $callback = function($arg) {
{
$map = array( $map = array(
'Hello world' => 6, 'Hello world' => 6,
'world' => 5, 'world' => 5,
); );
return $map[$arg]; return $map[$arg];
}; };

View File

@@ -11,8 +11,6 @@
namespace Monolog\Handler; namespace Monolog\Handler;
use Monolog\Logger;
class SyslogHandlerTest extends \PHPUnit_Framework_TestCase class SyslogHandlerTest extends \PHPUnit_Framework_TestCase
{ {
/** /**

View File

@@ -127,6 +127,7 @@ class LoggerTest extends \PHPUnit_Framework_TestCase
$logger->pushHandler($handler); $logger->pushHandler($handler);
$logger->pushProcessor(function($record) { $logger->pushProcessor(function($record) {
$record['extra']['win'] = true; $record['extra']['win'] = true;
return $record; return $record;
}); });
$logger->addError('test'); $logger->addError('test');

View File

@@ -21,6 +21,7 @@ class IntrospectionProcessorTest extends TestCase
$processor = new IntrospectionProcessor(); $processor = new IntrospectionProcessor();
$handler = new TestHandler(); $handler = new TestHandler();
$handler->pushProcessor($processor); $handler->pushProcessor($processor);
return $handler; return $handler;
} }
@@ -31,7 +32,7 @@ class IntrospectionProcessorTest extends TestCase
$tester->test($handler, $this->getRecord()); $tester->test($handler, $this->getRecord());
list($record) = $handler->getRecords(); list($record) = $handler->getRecords();
$this->assertEquals(__FILE__, $record['extra']['file']); $this->assertEquals(__FILE__, $record['extra']['file']);
$this->assertEquals(57, $record['extra']['line']); $this->assertEquals(58, $record['extra']['line']);
$this->assertEquals('Acme\Tester', $record['extra']['class']); $this->assertEquals('Acme\Tester', $record['extra']['class']);
$this->assertEquals('test', $record['extra']['function']); $this->assertEquals('test', $record['extra']['function']);
} }
@@ -42,7 +43,7 @@ class IntrospectionProcessorTest extends TestCase
\Acme\tester($handler, $this->getRecord()); \Acme\tester($handler, $this->getRecord());
list($record) = $handler->getRecords(); list($record) = $handler->getRecords();
$this->assertEquals(__FILE__, $record['extra']['file']); $this->assertEquals(__FILE__, $record['extra']['file']);
$this->assertEquals(63, $record['extra']['line']); $this->assertEquals(64, $record['extra']['line']);
$this->assertEquals(null, $record['extra']['class']); $this->assertEquals(null, $record['extra']['class']);
$this->assertEquals('Acme\tester', $record['extra']['function']); $this->assertEquals('Acme\tester', $record['extra']['function']);
} }
@@ -52,7 +53,7 @@ namespace Acme;
class Tester class Tester
{ {
function test($handler, $record) public function test($handler, $record)
{ {
$handler->handle($record); $handler->handle($record);
} }