From 1c75491af20f2959a28ad153377b160b26ae84b2 Mon Sep 17 00:00:00 2001 From: Dmitry Ivanov Date: Wed, 29 Jun 2016 12:27:49 +0300 Subject: [PATCH 1/5] HtmlFormatter methods accessibility Please, make them protected instead of private to enable comfortable overriding of HtmlFormatter class. --- src/Monolog/Formatter/HtmlFormatter.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Monolog/Formatter/HtmlFormatter.php b/src/Monolog/Formatter/HtmlFormatter.php index 3251907b..3eec95f6 100644 --- a/src/Monolog/Formatter/HtmlFormatter.php +++ b/src/Monolog/Formatter/HtmlFormatter.php @@ -51,7 +51,7 @@ class HtmlFormatter extends NormalizerFormatter * @param bool $escapeTd false if td content must not be html escaped * @return string */ - private function addRow($th, $td = ' ', $escapeTd = true) + protected function addRow($th, $td = ' ', $escapeTd = true) { $th = htmlspecialchars($th, ENT_NOQUOTES, 'UTF-8'); if ($escapeTd) { @@ -68,7 +68,7 @@ class HtmlFormatter extends NormalizerFormatter * @param int $level Error level * @return string */ - private function addTitle($title, $level) + protected function addTitle($title, $level) { $title = htmlspecialchars($title, ENT_NOQUOTES, 'UTF-8'); From d9be260f3d8adf94b141d72a8bcac905bf79a4c9 Mon Sep 17 00:00:00 2001 From: s4msung Date: Mon, 27 Jun 2016 18:22:06 +0200 Subject: [PATCH 2/5] include $context in error_handler --- src/Monolog/ErrorHandler.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Monolog/ErrorHandler.php b/src/Monolog/ErrorHandler.php index f21eb285..541a57b0 100644 --- a/src/Monolog/ErrorHandler.php +++ b/src/Monolog/ErrorHandler.php @@ -1,3 +1,4 @@ + hasFatalErrorHandler || !in_array($code, self::$fatalErrors, true)) { $level = isset($this->errorLevelMap[$code]) ? $this->errorLevelMap[$code] : LogLevel::CRITICAL; - $this->logger->log($level, self::codeToString($code).': '.$message, array('code' => $code, 'message' => $message, 'file' => $file, 'line' => $line)); + $this->logger->log($level, self::codeToString($code).': '.$message, array('code' => $code, 'message' => $message, 'file' => $file, 'line' => $line, 'context' => $context)); } if ($this->previousErrorHandler === true) { From 69fb2aa1c16dc532b0a9f8d704cfe51407e3b604 Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Sat, 2 Jul 2016 14:48:22 +0100 Subject: [PATCH 3/5] Fix GroupHandler::handleBatch when the handler has processors, fixes #814 --- src/Monolog/Handler/GroupHandler.php | 10 ++++++++++ tests/Monolog/Handler/GroupHandlerTest.php | 23 ++++++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/src/Monolog/Handler/GroupHandler.php b/src/Monolog/Handler/GroupHandler.php index 48e7b8e5..663f5a92 100644 --- a/src/Monolog/Handler/GroupHandler.php +++ b/src/Monolog/Handler/GroupHandler.php @@ -75,6 +75,16 @@ class GroupHandler extends AbstractHandler */ public function handleBatch(array $records) { + if ($this->processors) { + $processed = array(); + foreach ($records as $record) { + foreach ($this->processors as $processor) { + $processed[] = call_user_func($processor, $record); + } + } + $records = $processed; + } + foreach ($this->handlers as $handler) { $handler->handleBatch($records); } diff --git a/tests/Monolog/Handler/GroupHandlerTest.php b/tests/Monolog/Handler/GroupHandlerTest.php index c6298a6e..a1b86176 100644 --- a/tests/Monolog/Handler/GroupHandlerTest.php +++ b/tests/Monolog/Handler/GroupHandlerTest.php @@ -86,4 +86,27 @@ class GroupHandlerTest extends TestCase $records = $test->getRecords(); $this->assertTrue($records[0]['extra']['foo']); } + + /** + * @covers Monolog\Handler\GroupHandler::handle + */ + public function testHandleBatchUsesProcessors() + { + $testHandlers = array(new TestHandler(), new TestHandler()); + $handler = new GroupHandler($testHandlers); + $handler->pushProcessor(function ($record) { + $record['extra']['foo'] = true; + + return $record; + }); + $handler->handleBatch(array($this->getRecord(Logger::DEBUG), $this->getRecord(Logger::INFO))); + foreach ($testHandlers as $test) { + $this->assertTrue($test->hasDebugRecords()); + $this->assertTrue($test->hasInfoRecords()); + $this->assertTrue(count($test->getRecords()) === 2); + $records = $test->getRecords(); + $this->assertTrue($records[0]['extra']['foo']); + $this->assertTrue($records[1]['extra']['foo']); + } + } } From 68459e5cbb49b85581bc7f6df998680349dfd4b5 Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Sat, 2 Jul 2016 14:59:31 +0100 Subject: [PATCH 4/5] Update CHANGELOG --- CHANGELOG.mdown | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/CHANGELOG.mdown b/CHANGELOG.mdown index 4b574105..7624cac4 100644 --- a/CHANGELOG.mdown +++ b/CHANGELOG.mdown @@ -1,3 +1,13 @@ +### 1.20.0 (2016-07-02) + + * Added FingersCrossedHandler::activate() to manually trigger the handler regardless of the activation policy + * Added StreamHandler::getUrl to retrieve the stream's URL + * Added ability to override addRow/addTitle in HtmlFormatter + * Added the $context to context information when the ErrorHandler handles a regular php error + * Deprecated RotatingFileHandler::setFilenameFormat to only support 3 formats: Y, Y-m and Y-m-d + * Fixed WhatFailureGroupHandler to work with PHP7 throwables + * Fixed a few minor bugs + ### 1.19.0 (2016-04-12) * Break: StreamHandler will not close streams automatically that it does not own. If you pass in a stream (not a path/url), then it will not close it for you. You can retrieve those using getStream() if needed From 55841909e2bcde01b5318c35f2b74f8ecc86e037 Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Sat, 2 Jul 2016 15:02:10 +0100 Subject: [PATCH 5/5] Undo accidental linebreak --- src/Monolog/ErrorHandler.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Monolog/ErrorHandler.php b/src/Monolog/ErrorHandler.php index 541a57b0..715b93a9 100644 --- a/src/Monolog/ErrorHandler.php +++ b/src/Monolog/ErrorHandler.php @@ -1,4 +1,3 @@ -