diff --git a/src/Monolog/Formatter/FormatterInterface.php b/src/Monolog/Formatter/FormatterInterface.php index fd8233ff..75231c2f 100644 --- a/src/Monolog/Formatter/FormatterInterface.php +++ b/src/Monolog/Formatter/FormatterInterface.php @@ -11,6 +11,11 @@ namespace Monolog\Formatter; +/** + * Interface for formatters + * + * @author Jordi Boggiano + */ interface FormatterInterface { function format($message); diff --git a/src/Monolog/Formatter/JsonFormatter.php b/src/Monolog/Formatter/JsonFormatter.php index 335145ce..7e3f067f 100644 --- a/src/Monolog/Formatter/JsonFormatter.php +++ b/src/Monolog/Formatter/JsonFormatter.php @@ -13,11 +13,18 @@ namespace Monolog\Formatter; use Monolog\Logger; +/** + * Encodes whatever message data is passed to it as json + * + * This can be useful to log to databases or remote APIs + * + * @author Jordi Boggiano + */ class JsonFormatter implements FormatterInterface { public function format($message) { - $message['message'] = json_encode($message['message']); + $message['message'] = json_encode($message); return $message; } } diff --git a/src/Monolog/Formatter/LineFormatter.php b/src/Monolog/Formatter/LineFormatter.php index e272fdc6..08f70f75 100644 --- a/src/Monolog/Formatter/LineFormatter.php +++ b/src/Monolog/Formatter/LineFormatter.php @@ -13,6 +13,13 @@ namespace Monolog\Formatter; use Monolog\Logger; +/** + * Formats incoming messages into a one-line string + * + * This is especially useful for logging to files + * + * @author Jordi Boggiano + */ class LineFormatter implements FormatterInterface { const SIMPLE_FORMAT = "[%datetime%] %channel%.%level_name%: %message%\n"; diff --git a/src/Monolog/Handler/AbstractHandler.php b/src/Monolog/Handler/AbstractHandler.php index da4aed09..a0d4489d 100644 --- a/src/Monolog/Handler/AbstractHandler.php +++ b/src/Monolog/Handler/AbstractHandler.php @@ -14,6 +14,13 @@ namespace Monolog\Handler; use Monolog\Logger; use Monolog\Formatter\LineFormatter; +/** + * Base Handler class providing the Handler structure + * + * Classes extending it should (in most cases) only implement write($message) + * + * @author Jordi Boggiano + */ abstract class AbstractHandler implements HandlerInterface { protected $level; diff --git a/src/Monolog/Handler/FingersCrossedHandler.php b/src/Monolog/Handler/FingersCrossedHandler.php index de6398e4..93fca55a 100644 --- a/src/Monolog/Handler/FingersCrossedHandler.php +++ b/src/Monolog/Handler/FingersCrossedHandler.php @@ -14,7 +14,7 @@ namespace Monolog\Handler; use Monolog\Logger; /** - * FingersCrossedHandler buffers all messages until a certain level is reached + * Buffers all messages until a certain level is reached * * The advantage of this approach is that you don't get any clutter in your log files. * Only requests which actually trigger an error (or whatever your actionLevel is) will be @@ -51,7 +51,7 @@ class FingersCrossedHandler extends AbstractHandler * on, unless reset() is called, all messages are passed to the wrapped handler. * * @param array $message Message - * @return Boolean Whether the next handler in the stack should be called. + * @return Boolean Whether the message was handled */ public function handle($message) { @@ -73,7 +73,10 @@ class FingersCrossedHandler extends AbstractHandler } else { $this->handler->handle($message); } - return false === $this->bubble; + if ($this->bubble && $this->parent) { + $this->parent->handle($originalMessage); + } + return true; } /** diff --git a/src/Monolog/Handler/HandlerInterface.php b/src/Monolog/Handler/HandlerInterface.php index 976790ef..077db44b 100644 --- a/src/Monolog/Handler/HandlerInterface.php +++ b/src/Monolog/Handler/HandlerInterface.php @@ -11,6 +11,11 @@ namespace Monolog\Handler; +/** + * Interface that all Monolog Handlers must implement + * + * @author Jordi Boggiano + */ interface HandlerInterface { public function getHandler($message); diff --git a/src/Monolog/Handler/NullHandler.php b/src/Monolog/Handler/NullHandler.php index cd7229e2..36ff1d06 100644 --- a/src/Monolog/Handler/NullHandler.php +++ b/src/Monolog/Handler/NullHandler.php @@ -13,14 +13,25 @@ namespace Monolog\Handler; use Monolog\Logger; +/** + * Blackhole + * + * Any message it can handle will be thrown away. This can be used + * to put on top of an existing stack to override it temporarily. + * + * @author Jordi Boggiano + */ class NullHandler extends AbstractHandler { public function handle($message) { if ($message['level'] < $this->level) { - return false; + return $this->parent ? $this->parent->handle($message) : false; } - return false === $this->bubble; + if ($this->bubble && $this->parent) { + $this->parent->handle($originalMessage); + } + return true; } public function write($message) diff --git a/src/Monolog/Handler/RotatingFileHandler.php b/src/Monolog/Handler/RotatingFileHandler.php index 694744d1..09ff1643 100644 --- a/src/Monolog/Handler/RotatingFileHandler.php +++ b/src/Monolog/Handler/RotatingFileHandler.php @@ -11,6 +11,11 @@ namespace Monolog\Handler; +/** + * Stores logs to files that are rotated every n day/week/month + * + * @author Jordi Boggiano + */ class RotatingFileHandler extends StreamHandler { protected $rotation; diff --git a/src/Monolog/Handler/StreamHandler.php b/src/Monolog/Handler/StreamHandler.php index 1a1d527f..0916ad92 100644 --- a/src/Monolog/Handler/StreamHandler.php +++ b/src/Monolog/Handler/StreamHandler.php @@ -14,6 +14,13 @@ namespace Monolog\Handler; use Monolog\Formatter\SimpleFormatter; use Monolog\Logger; +/** + * Stores to any stream resource + * + * Can be used to store into php://stderr, remote and local files, etc. + * + * @author Jordi Boggiano + */ class StreamHandler extends AbstractHandler { protected $stream; diff --git a/src/Monolog/Handler/TestHandler.php b/src/Monolog/Handler/TestHandler.php index 6d026b0d..d2f5a4ac 100644 --- a/src/Monolog/Handler/TestHandler.php +++ b/src/Monolog/Handler/TestHandler.php @@ -14,7 +14,7 @@ namespace Monolog\Handler; use Monolog\Logger; /** - * TestHandler is used for testing purposes. + * Used for testing purposes. * * It records all messages and gives you access to them for verification. * diff --git a/src/Monolog/Logger.php b/src/Monolog/Logger.php index 5b52644c..a8f5832d 100644 --- a/src/Monolog/Logger.php +++ b/src/Monolog/Logger.php @@ -14,6 +14,14 @@ namespace Monolog; use Monolog\Handler\HandlerInterface; use Monolog\Handler\StreamHandler; +/** + * Monolog log channel + * + * It contains a stack of Handlers and a stack of Processors, + * and uses them to store messages that are added to it. + * + * @author Jordi Boggiano + */ class Logger { /** diff --git a/src/Monolog/Processor/WebProcessor.php b/src/Monolog/Processor/WebProcessor.php index d4634946..2bfa4e46 100644 --- a/src/Monolog/Processor/WebProcessor.php +++ b/src/Monolog/Processor/WebProcessor.php @@ -11,6 +11,11 @@ namespace Monolog\Processor; +/** + * Injects url/method and remote IP of the current web request in all messages + * + * @author Jordi Boggiano + */ class WebProcessor { public function __invoke($message, $handler) diff --git a/tests/Monolog/Formatter/JsonFormatterTest.php b/tests/Monolog/Formatter/JsonFormatterTest.php index df08ebeb..67c15973 100644 --- a/tests/Monolog/Formatter/JsonFormatterTest.php +++ b/tests/Monolog/Formatter/JsonFormatterTest.php @@ -18,13 +18,13 @@ class JsonFormatterTest extends \PHPUnit_Framework_TestCase public function testFormat() { $formatter = new JsonFormatter(); - $message = $formatter->format(array( + $message = $formatter->format($msg = array( 'level_name' => 'WARNING', 'channel' => 'log', 'message' => array('foo'), 'datetime' => new \DateTime, 'extra' => array(), )); - $this->assertEquals(json_encode(array('foo')), $message['message']); + $this->assertEquals(json_encode($msg), $message['message']); } } diff --git a/tests/Monolog/Handler/NullHandlerTest.php b/tests/Monolog/Handler/NullHandlerTest.php index 6e3837f7..e2ceb7e0 100644 --- a/tests/Monolog/Handler/NullHandlerTest.php +++ b/tests/Monolog/Handler/NullHandlerTest.php @@ -27,12 +27,6 @@ class NullHandlerTest extends \PHPUnit_Framework_TestCase $this->assertFalse($handler->handle($this->getMessage(Logger::DEBUG))); } - public function testHandleBubbling() - { - $handler = new NullHandler(Logger::DEBUG, true); - $this->assertFalse($handler->handle($this->getMessage())); - } - /** * No-op test for coverage */