From c677398c76961bcbe55ec1da2cedce5585df6577 Mon Sep 17 00:00:00 2001 From: Nils Adermann Date: Thu, 14 Apr 2016 16:56:59 -0400 Subject: [PATCH 01/12] Provide means to manually activate a FingersCrossedHandler This is useful if you have a FingersCrossedHandler set up and some where in your application are interested in all output regardless of whether the threshold is actually reached. For example to temporarily debug some problem. One can replace the handler in that spot, but this is signifcantly easier to use. --- src/Monolog/Handler/FingersCrossedHandler.php | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/Monolog/Handler/FingersCrossedHandler.php b/src/Monolog/Handler/FingersCrossedHandler.php index 30a85dd6..6036c15e 100644 --- a/src/Monolog/Handler/FingersCrossedHandler.php +++ b/src/Monolog/Handler/FingersCrossedHandler.php @@ -36,6 +36,7 @@ class FingersCrossedHandler extends AbstractHandler protected $buffer = array(); protected $stopBuffering; protected $passthruLevel; + protected $overrideActivated = false; /** * @param callable|HandlerInterface $handler Handler or factory callable($record, $fingersCrossedHandler). @@ -79,6 +80,14 @@ class FingersCrossedHandler extends AbstractHandler return true; } + /** + * Manually activate this logger regardless of the activation strategy + */ + public function activate() + { + $this->overrideActivated = true; + } + /** * {@inheritdoc} */ @@ -95,7 +104,7 @@ class FingersCrossedHandler extends AbstractHandler if ($this->bufferSize > 0 && count($this->buffer) > $this->bufferSize) { array_shift($this->buffer); } - if ($this->activationStrategy->isHandlerActivated($record)) { + if ($this->overrideActivated || $this->activationStrategy->isHandlerActivated($record)) { if ($this->stopBuffering) { $this->buffering = false; } From e0b521ba53b375421c41e63544b5e85d0a670f09 Mon Sep 17 00:00:00 2001 From: Nils Adermann Date: Thu, 14 Apr 2016 17:02:29 -0400 Subject: [PATCH 02/12] Add a test that verifies manual overriding of activation strategy works --- .../Handler/FingersCrossedHandlerTest.php | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/tests/Monolog/Handler/FingersCrossedHandlerTest.php b/tests/Monolog/Handler/FingersCrossedHandlerTest.php index 8e31e9b8..f87c632e 100644 --- a/tests/Monolog/Handler/FingersCrossedHandlerTest.php +++ b/tests/Monolog/Handler/FingersCrossedHandlerTest.php @@ -173,6 +173,22 @@ class FingersCrossedHandlerTest extends TestCase $this->assertTrue($test->hasWarningRecords()); } + /** + * @covers Monolog\Handler\FingersCrossedHandler::__construct + * @covers Monolog\Handler\FingersCrossedHandler::activate + */ + public function testOverrideActivationStrategy() + { + $test = new TestHandler(); + $handler = new FingersCrossedHandler($test, new ErrorLevelActivationStrategy('warning')); + $handler->handle($this->getRecord(Logger::DEBUG)); + $this->assertFalse($test->hasDebugRecords()); + $handler->activate(); + $handler->handle($this->getRecord(Logger::INFO)); + $this->assertTrue($test->hasDebugRecords()); + $this->assertTrue($test->hasInfoRecords()); + } + /** * @covers Monolog\Handler\FingersCrossed\ChannelLevelActivationStrategy::__construct * @covers Monolog\Handler\FingersCrossed\ChannelLevelActivationStrategy::isHandlerActivated From 04dedae4a81eeb2135eeb10b5323935f879ced0a Mon Sep 17 00:00:00 2001 From: Andrzej Kupczyk Date: Fri, 15 Apr 2016 18:45:46 +0200 Subject: [PATCH 03/12] Fixed $handler property visibility According to the given example, $handler property should not be private. --- src/Monolog/Handler/HandlerWrapper.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Monolog/Handler/HandlerWrapper.php b/src/Monolog/Handler/HandlerWrapper.php index ad2bd814..56bc2704 100644 --- a/src/Monolog/Handler/HandlerWrapper.php +++ b/src/Monolog/Handler/HandlerWrapper.php @@ -33,7 +33,7 @@ class HandlerWrapper implements HandlerInterface /** * @var HandlerInterface */ - private $handler; + protected $handler; /** * HandlerWrapper constructor. From abb58081fe729573c830107a99f0331a3eda4005 Mon Sep 17 00:00:00 2001 From: Nils Adermann Date: Fri, 15 Apr 2016 14:05:55 -0400 Subject: [PATCH 04/12] Extract fingerscrossed activation into its own method callable from outside --- src/Monolog/Handler/FingersCrossedHandler.php | 32 +++++++++++-------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/src/Monolog/Handler/FingersCrossedHandler.php b/src/Monolog/Handler/FingersCrossedHandler.php index 6036c15e..8a3b69ca 100644 --- a/src/Monolog/Handler/FingersCrossedHandler.php +++ b/src/Monolog/Handler/FingersCrossedHandler.php @@ -36,7 +36,6 @@ class FingersCrossedHandler extends AbstractHandler protected $buffer = array(); protected $stopBuffering; protected $passthruLevel; - protected $overrideActivated = false; /** * @param callable|HandlerInterface $handler Handler or factory callable($record, $fingersCrossedHandler). @@ -85,7 +84,22 @@ class FingersCrossedHandler extends AbstractHandler */ public function activate() { - $this->overrideActivated = true; + if ($this->stopBuffering) { + $this->buffering = false; + } + if (!$this->handler instanceof HandlerInterface) { + $record = end($this->buffer); + if ($record === false) { + $record = null; + } + + $this->handler = call_user_func($this->handler, $record, $this); + if (!$this->handler instanceof HandlerInterface) { + throw new \RuntimeException("The factory callable should return a HandlerInterface"); + } + } + $this->handler->handleBatch($this->buffer); + $this->buffer = array(); } /** @@ -104,18 +118,8 @@ class FingersCrossedHandler extends AbstractHandler if ($this->bufferSize > 0 && count($this->buffer) > $this->bufferSize) { array_shift($this->buffer); } - if ($this->overrideActivated || $this->activationStrategy->isHandlerActivated($record)) { - if ($this->stopBuffering) { - $this->buffering = false; - } - if (!$this->handler instanceof HandlerInterface) { - $this->handler = call_user_func($this->handler, $record, $this); - if (!$this->handler instanceof HandlerInterface) { - throw new \RuntimeException("The factory callable should return a HandlerInterface"); - } - } - $this->handler->handleBatch($this->buffer); - $this->buffer = array(); + if ($this->activationStrategy->isHandlerActivated($record)) { + $this->activate($record); } } else { $this->handler->handle($record); From e7c326782f72938741a96c3157af7fd186d170bc Mon Sep 17 00:00:00 2001 From: Nils Adermann Date: Fri, 15 Apr 2016 14:11:04 -0400 Subject: [PATCH 05/12] FingersCrossed: Adapt test for extraction of activate from handle() --- tests/Monolog/Handler/FingersCrossedHandlerTest.php | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/tests/Monolog/Handler/FingersCrossedHandlerTest.php b/tests/Monolog/Handler/FingersCrossedHandlerTest.php index f87c632e..b92bf437 100644 --- a/tests/Monolog/Handler/FingersCrossedHandlerTest.php +++ b/tests/Monolog/Handler/FingersCrossedHandlerTest.php @@ -22,6 +22,7 @@ class FingersCrossedHandlerTest extends TestCase /** * @covers Monolog\Handler\FingersCrossedHandler::__construct * @covers Monolog\Handler\FingersCrossedHandler::handle + * @covers Monolog\Handler\FingersCrossedHandler::activate */ public function testHandleBuffers() { @@ -39,6 +40,7 @@ class FingersCrossedHandlerTest extends TestCase /** * @covers Monolog\Handler\FingersCrossedHandler::handle + * @covers Monolog\Handler\FingersCrossedHandler::activate */ public function testHandleStopsBufferingAfterTrigger() { @@ -53,6 +55,7 @@ class FingersCrossedHandlerTest extends TestCase /** * @covers Monolog\Handler\FingersCrossedHandler::handle + * @covers Monolog\Handler\FingersCrossedHandler::activate * @covers Monolog\Handler\FingersCrossedHandler::reset */ public function testHandleRestartBufferingAfterReset() @@ -71,6 +74,7 @@ class FingersCrossedHandlerTest extends TestCase /** * @covers Monolog\Handler\FingersCrossedHandler::handle + * @covers Monolog\Handler\FingersCrossedHandler::activate */ public function testHandleRestartBufferingAfterBeingTriggeredWhenStopBufferingIsDisabled() { @@ -87,6 +91,7 @@ class FingersCrossedHandlerTest extends TestCase /** * @covers Monolog\Handler\FingersCrossedHandler::handle + * @covers Monolog\Handler\FingersCrossedHandler::activate */ public function testHandleBufferLimit() { @@ -103,6 +108,7 @@ class FingersCrossedHandlerTest extends TestCase /** * @covers Monolog\Handler\FingersCrossedHandler::handle + * @covers Monolog\Handler\FingersCrossedHandler::activate */ public function testHandleWithCallback() { @@ -121,6 +127,7 @@ class FingersCrossedHandlerTest extends TestCase /** * @covers Monolog\Handler\FingersCrossedHandler::handle + * @covers Monolog\Handler\FingersCrossedHandler::activate * @expectedException RuntimeException */ public function testHandleWithBadCallbackThrowsException() @@ -184,8 +191,8 @@ class FingersCrossedHandlerTest extends TestCase $handler->handle($this->getRecord(Logger::DEBUG)); $this->assertFalse($test->hasDebugRecords()); $handler->activate(); - $handler->handle($this->getRecord(Logger::INFO)); $this->assertTrue($test->hasDebugRecords()); + $handler->handle($this->getRecord(Logger::INFO)); $this->assertTrue($test->hasInfoRecords()); } @@ -225,6 +232,7 @@ class FingersCrossedHandlerTest extends TestCase /** * @covers Monolog\Handler\FingersCrossedHandler::handle + * @covers Monolog\Handler\FingersCrossedHandler::activate */ public function testHandleUsesProcessors() { From 0fc6734c6f2c133a73e073472f33ecd87247894d Mon Sep 17 00:00:00 2001 From: Nils Adermann Date: Wed, 20 Apr 2016 15:00:33 -0400 Subject: [PATCH 06/12] FingersCrossedHandler: Clean up code --- src/Monolog/Handler/FingersCrossedHandler.php | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/Monolog/Handler/FingersCrossedHandler.php b/src/Monolog/Handler/FingersCrossedHandler.php index 8a3b69ca..d1dcaacf 100644 --- a/src/Monolog/Handler/FingersCrossedHandler.php +++ b/src/Monolog/Handler/FingersCrossedHandler.php @@ -88,10 +88,7 @@ class FingersCrossedHandler extends AbstractHandler $this->buffering = false; } if (!$this->handler instanceof HandlerInterface) { - $record = end($this->buffer); - if ($record === false) { - $record = null; - } + $record = end($this->buffer) ?: null; $this->handler = call_user_func($this->handler, $record, $this); if (!$this->handler instanceof HandlerInterface) { @@ -119,7 +116,7 @@ class FingersCrossedHandler extends AbstractHandler array_shift($this->buffer); } if ($this->activationStrategy->isHandlerActivated($record)) { - $this->activate($record); + $this->activate(); } } else { $this->handler->handle($record); From e2c575b50542f84bd2620d3ef8d2e7080d437e43 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Filip=20Proch=C3=A1zka?= Date: Fri, 13 May 2016 21:43:07 +0200 Subject: [PATCH 07/12] Catch Throwable --- src/Monolog/Handler/AbstractHandler.php | 2 ++ src/Monolog/Handler/WhatFailureGroupHandler.php | 4 ++++ 2 files changed, 6 insertions(+) diff --git a/src/Monolog/Handler/AbstractHandler.php b/src/Monolog/Handler/AbstractHandler.php index 525e4f99..758a425c 100644 --- a/src/Monolog/Handler/AbstractHandler.php +++ b/src/Monolog/Handler/AbstractHandler.php @@ -169,6 +169,8 @@ abstract class AbstractHandler implements HandlerInterface $this->close(); } catch (\Exception $e) { // do nothing + } catch (\Throwable $e) { + // do nothing } } diff --git a/src/Monolog/Handler/WhatFailureGroupHandler.php b/src/Monolog/Handler/WhatFailureGroupHandler.php index 05a88173..2732ba3d 100644 --- a/src/Monolog/Handler/WhatFailureGroupHandler.php +++ b/src/Monolog/Handler/WhatFailureGroupHandler.php @@ -35,6 +35,8 @@ class WhatFailureGroupHandler extends GroupHandler $handler->handle($record); } catch (\Exception $e) { // What failure? + } catch (\Throwable $e) { + // What failure? } } @@ -51,6 +53,8 @@ class WhatFailureGroupHandler extends GroupHandler $handler->handleBatch($records); } catch (\Exception $e) { // What failure? + } catch (\Throwable $e) { + // What failure? } } } From 83a24937ba50ab39f450faf8c448d6c68a293ea0 Mon Sep 17 00:00:00 2001 From: Remon van de Kamp Date: Fri, 20 May 2016 20:13:19 +0200 Subject: [PATCH 08/12] Add deprecation errors on RotatingFileHandler (#774) * Add deprecation errors when attempting to set dateFormats of fileFormats that break the possibility of rotating easily in RotatingFileHandler. Version 2.x of Monolog will throw `\InvalidArgumentException`s in these cases. --- src/Monolog/Handler/RotatingFileHandler.php | 18 +++ .../Handler/RotatingFileHandlerTest.php | 132 ++++++++++++++++-- 2 files changed, 140 insertions(+), 10 deletions(-) diff --git a/src/Monolog/Handler/RotatingFileHandler.php b/src/Monolog/Handler/RotatingFileHandler.php index 22e6c3dc..cd938057 100644 --- a/src/Monolog/Handler/RotatingFileHandler.php +++ b/src/Monolog/Handler/RotatingFileHandler.php @@ -24,6 +24,10 @@ use Monolog\Logger; */ class RotatingFileHandler extends StreamHandler { + const FILE_PER_DAY = 'Y-m-d'; + const FILE_PER_MONTH = 'Y-m'; + const FILE_PER_YEAR = 'Y'; + protected $filename; protected $maxFiles; protected $mustRotate; @@ -64,6 +68,20 @@ class RotatingFileHandler extends StreamHandler public function setFilenameFormat($filenameFormat, $dateFormat) { + if (!in_array($dateFormat, array(self::FILE_PER_DAY, self::FILE_PER_MONTH, self::FILE_PER_YEAR))) { + trigger_error( + 'Invalid date format - format should be one of '. + 'RotatingFileHandler::FILE_PER_DAY, RotatingFileHandler::FILE_PER_MONTH '. + 'or RotatingFileHandler::FILE_PER_YEAR.', + E_USER_DEPRECATED + ); + } + if (substr_count($filenameFormat, '{date}') === 0) { + trigger_error( + 'Invalid filename format - format should contain at least `{date}`, because otherwise rotating is impossible.', + E_USER_DEPRECATED + ); + } $this->filenameFormat = $filenameFormat; $this->dateFormat = $dateFormat; $this->url = $this->getTimedFilename(); diff --git a/tests/Monolog/Handler/RotatingFileHandlerTest.php b/tests/Monolog/Handler/RotatingFileHandlerTest.php index f4cefda1..96e6dff4 100644 --- a/tests/Monolog/Handler/RotatingFileHandlerTest.php +++ b/tests/Monolog/Handler/RotatingFileHandlerTest.php @@ -12,19 +12,52 @@ namespace Monolog\Handler; use Monolog\TestCase; +use PHPUnit_Framework_Error_Deprecated; /** * @covers Monolog\Handler\RotatingFileHandler */ class RotatingFileHandlerTest extends TestCase { + /** + * This var should be private but then the anonymous function + * in the `setUp` method won't be able to set it. `$this` cant't + * be used in the anonymous function in `setUp` because PHP 5.3 + * does not support it. + */ + public $lastError; + public function setUp() { $dir = __DIR__.'/Fixtures'; chmod($dir, 0777); if (!is_writable($dir)) { - $this->markTestSkipped($dir.' must be writeable to test the RotatingFileHandler.'); + $this->markTestSkipped($dir.' must be writable to test the RotatingFileHandler.'); } + $this->lastError = null; + $self = $this; + // workaround with &$self used for PHP 5.3 + set_error_handler(function($code, $message) use (&$self) { + $self->lastError = array( + 'code' => $code, + 'message' => $message, + ); + }); + } + + private function assertErrorWasTriggered($code, $message) + { + if (empty($this->lastError)) { + $this->fail( + sprintf( + 'Failed asserting that error with code `%d` and message `%s` was triggered', + $code, + $message + ) + ); + } + $this->assertEquals($code, $this->lastError['code'], sprintf('Expected an error with code %d to be triggered, got `%s` instead', $code, $this->lastError['code'])); + $this->assertEquals($message, $this->lastError['message'], sprintf('Expected an error with message `%d` to be triggered, got `%s` instead', $message, $this->lastError['message'])); } public function testRotationCreatesNewFile() @@ -43,14 +76,14 @@ class RotatingFileHandlerTest extends TestCase /** * @dataProvider rotationTests */ - public function testRotation($createFile) + public function testRotation($createFile, $dateFormat, $timeCallback) { - touch($old1 = __DIR__.'/Fixtures/foo-'.date('Y-m-d', time() - 86400).'.rot'); - touch($old2 = __DIR__.'/Fixtures/foo-'.date('Y-m-d', time() - 86400 * 2).'.rot'); - touch($old3 = __DIR__.'/Fixtures/foo-'.date('Y-m-d', time() - 86400 * 3).'.rot'); - touch($old4 = __DIR__.'/Fixtures/foo-'.date('Y-m-d', time() - 86400 * 4).'.rot'); + touch($old1 = __DIR__.'/Fixtures/foo-'.date($dateFormat, $timeCallback(-1)).'.rot'); + touch($old2 = __DIR__.'/Fixtures/foo-'.date($dateFormat, $timeCallback(-2)).'.rot'); + touch($old3 = __DIR__.'/Fixtures/foo-'.date($dateFormat, $timeCallback(-3)).'.rot'); + touch($old4 = __DIR__.'/Fixtures/foo-'.date($dateFormat, $timeCallback(-4)).'.rot'); - $log = __DIR__.'/Fixtures/foo-'.date('Y-m-d').'.rot'; + $log = __DIR__.'/Fixtures/foo-'.date($dateFormat).'.rot'; if ($createFile) { touch($log); @@ -58,6 +91,7 @@ class RotatingFileHandlerTest extends TestCase $handler = new RotatingFileHandler(__DIR__.'/Fixtures/foo.rot', 2); $handler->setFormatter($this->getIdentityFormatter()); + $handler->setFilenameFormat('{filename}-{date}', $dateFormat); $handler->handle($this->getRecord()); $handler->close(); @@ -72,11 +106,88 @@ class RotatingFileHandlerTest extends TestCase public function rotationTests() { + $now = time(); + $dayCallback = function($ago) use ($now) { + return $now + 86400 * $ago; + }; + $monthCallback = function($ago) { + return gmmktime(0, 0, 0, date('n') + $ago, date('d'), date('Y')); + }; + $yearCallback = function($ago) { + return gmmktime(0, 0, 0, date('n'), date('d'), date('Y') + $ago); + }; + return array( 'Rotation is triggered when the file of the current day is not present' - => array(true), - 'Rotation is not triggered when the file is already present' - => array(false), + => array(true, RotatingFileHandler::FILE_PER_DAY, $dayCallback), + 'Rotation is not triggered when the file of the current day is already present' + => array(false, RotatingFileHandler::FILE_PER_DAY, $dayCallback), + + 'Rotation is triggered when the file of the current month is not present' + => array(true, RotatingFileHandler::FILE_PER_MONTH, $monthCallback), + 'Rotation is not triggered when the file of the current month is already present' + => array(false, RotatingFileHandler::FILE_PER_MONTH, $monthCallback), + + 'Rotation is triggered when the file of the current year is not present' + => array(true, RotatingFileHandler::FILE_PER_YEAR, $yearCallback), + 'Rotation is not triggered when the file of the current year is already present' + => array(false, RotatingFileHandler::FILE_PER_YEAR, $yearCallback), + ); + } + + /** + * @dataProvider dateFormatProvider + */ + public function testAllowOnlyFixedDefinedDateFormats($dateFormat, $valid) + { + $handler = new RotatingFileHandler(__DIR__.'/Fixtures/foo.rot', 2); + $handler->setFilenameFormat('{filename}-{date}', $dateFormat); + if (!$valid) { + $this->assertErrorWasTriggered( + E_USER_DEPRECATED, + 'Invalid date format - format should be one of '. + 'RotatingFileHandler::FILE_PER_DAY, RotatingFileHandler::FILE_PER_MONTH '. + 'or RotatingFileHandler::FILE_PER_YEAR.' + ); + } + } + + public function dateFormatProvider() + { + return array( + array(RotatingFileHandler::FILE_PER_DAY, true), + array(RotatingFileHandler::FILE_PER_MONTH, true), + array(RotatingFileHandler::FILE_PER_YEAR, true), + array('m-d-Y', false), + array('Y-m-d-h-i', false) + ); + } + + /** + * @dataProvider filenameFormatProvider + */ + public function testDisallowFilenameFormatsWithoutDate($filenameFormat, $valid) + { + $handler = new RotatingFileHandler(__DIR__.'/Fixtures/foo.rot', 2); + $handler->setFilenameFormat($filenameFormat, RotatingFileHandler::FILE_PER_DAY); + if (!$valid) { + $this->assertErrorWasTriggered( + E_USER_DEPRECATED, + 'Invalid filename format - format should contain at least `{date}`, because otherwise rotating is impossible.' + ); + } + } + + public function filenameFormatProvider() + { + return array( + array('{filename}', false), + array('{filename}-{date}', true), + array('{date}', true), + array('foobar-{date}', true), + array('foo-{date}-bar', true), + array('{date}-foobar', true), + array('foobar', false), ); } @@ -95,5 +206,6 @@ class RotatingFileHandlerTest extends TestCase foreach (glob(__DIR__.'/Fixtures/*.rot') as $file) { unlink($file); } + restore_error_handler(); } } From 3101f1c09a0e5a2be11460c33ca09565db6780bf Mon Sep 17 00:00:00 2001 From: Leny BERNARD Date: Fri, 13 May 2016 15:17:26 +0200 Subject: [PATCH 09/12] check if val is null to avoid to set the string "null" instead of null --- src/Monolog/Formatter/GelfMessageFormatter.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Monolog/Formatter/GelfMessageFormatter.php b/src/Monolog/Formatter/GelfMessageFormatter.php index b4de509d..64e76652 100644 --- a/src/Monolog/Formatter/GelfMessageFormatter.php +++ b/src/Monolog/Formatter/GelfMessageFormatter.php @@ -106,7 +106,7 @@ class GelfMessageFormatter extends NormalizerFormatter } foreach ($record['extra'] as $key => $val) { - $val = is_scalar($val) ? $val : $this->toJson($val); + $val = is_scalar($val) || null === $val ? $val : $this->toJson($val); $len += strlen($this->extraPrefix . $key . $val); if ($len > self::MAX_LENGTH) { $message->setAdditional($this->extraPrefix . $key, substr($val, 0, self::MAX_LENGTH - $len)); @@ -116,7 +116,7 @@ class GelfMessageFormatter extends NormalizerFormatter } foreach ($record['context'] as $key => $val) { - $val = is_scalar($val) ? $val : $this->toJson($val); + $val = is_scalar($val) || null === $val ? $val : $this->toJson($val); $len += strlen($this->contextPrefix . $key . $val); if ($len > self::MAX_LENGTH) { $message->setAdditional($this->contextPrefix . $key, substr($val, 0, self::MAX_LENGTH - $len)); From 79f9492b74fd48c159451e99997a29888975a933 Mon Sep 17 00:00:00 2001 From: dasmfm <2@borisklimenko.ru> Date: Thu, 12 May 2016 14:17:22 +0300 Subject: [PATCH 10/12] Raven package renamed to sentry --- composer.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index 8631e27c..b488c38b 100644 --- a/composer.json +++ b/composer.json @@ -19,7 +19,7 @@ "require-dev": { "phpunit/phpunit": "~4.5", "graylog2/gelf-php": "~1.0", - "raven/raven": "^0.13", + "sentry/sentry": "^0.13", "ruflin/elastica": ">=0.90 <3.0", "doctrine/couchdb": "~1.0@dev", "aws/aws-sdk-php": "^2.4.9", @@ -32,7 +32,7 @@ "_": "phpunit/phpunit-mock-objects required in 2.3.0 due to https://github.com/sebastianbergmann/phpunit-mock-objects/issues/223 - needs hhvm 3.8+ on travis", "suggest": { "graylog2/gelf-php": "Allow sending log messages to a GrayLog2 server", - "raven/raven": "Allow sending log messages to a Sentry server", + "sentry/sentry": "Allow sending log messages to a Sentry server", "doctrine/couchdb": "Allow sending log messages to a CouchDB server", "ruflin/elastica": "Allow sending log messages to an Elastic Search server", "php-amqplib/php-amqplib": "Allow sending log messages to an AMQP server using php-amqplib", From 09c4cca32bf9d3e11f1e43c6d99d035c30ea859a Mon Sep 17 00:00:00 2001 From: Michael Moussa Date: Wed, 20 Apr 2016 11:31:39 -0400 Subject: [PATCH 11/12] Fix NewRelicHandler error when using LineFormatter --- src/Monolog/Handler/NewRelicHandler.php | 28 +++++++++++-------- tests/Monolog/Handler/NewRelicHandlerTest.php | 8 ++++++ 2 files changed, 24 insertions(+), 12 deletions(-) diff --git a/src/Monolog/Handler/NewRelicHandler.php b/src/Monolog/Handler/NewRelicHandler.php index 4eece765..e89684d8 100644 --- a/src/Monolog/Handler/NewRelicHandler.php +++ b/src/Monolog/Handler/NewRelicHandler.php @@ -91,23 +91,27 @@ class NewRelicHandler extends AbstractProcessingHandler newrelic_notice_error($record['message']); } - foreach ($record['formatted']['context'] as $key => $parameter) { - if (is_array($parameter) && $this->explodeArrays) { - foreach ($parameter as $paramKey => $paramValue) { - $this->setNewRelicParameter('context_' . $key . '_' . $paramKey, $paramValue); + if (isset($record['formatted']['context'])) { + foreach ($record['formatted']['context'] as $key => $parameter) { + if (is_array($parameter) && $this->explodeArrays) { + foreach ($parameter as $paramKey => $paramValue) { + $this->setNewRelicParameter('context_' . $key . '_' . $paramKey, $paramValue); + } + } else { + $this->setNewRelicParameter('context_' . $key, $parameter); } - } else { - $this->setNewRelicParameter('context_' . $key, $parameter); } } - foreach ($record['formatted']['extra'] as $key => $parameter) { - if (is_array($parameter) && $this->explodeArrays) { - foreach ($parameter as $paramKey => $paramValue) { - $this->setNewRelicParameter('extra_' . $key . '_' . $paramKey, $paramValue); + if (isset($record['formatted']['extra'])) { + foreach ($record['formatted']['extra'] as $key => $parameter) { + if (is_array($parameter) && $this->explodeArrays) { + foreach ($parameter as $paramKey => $paramValue) { + $this->setNewRelicParameter('extra_' . $key . '_' . $paramKey, $paramValue); + } + } else { + $this->setNewRelicParameter('extra_' . $key, $parameter); } - } else { - $this->setNewRelicParameter('extra_' . $key, $parameter); } } } diff --git a/tests/Monolog/Handler/NewRelicHandlerTest.php b/tests/Monolog/Handler/NewRelicHandlerTest.php index 4eda6155..4d3a615f 100644 --- a/tests/Monolog/Handler/NewRelicHandlerTest.php +++ b/tests/Monolog/Handler/NewRelicHandlerTest.php @@ -11,6 +11,7 @@ namespace Monolog\Handler; +use Monolog\Formatter\LineFormatter; use Monolog\TestCase; use Monolog\Logger; @@ -104,6 +105,13 @@ class NewRelicHandlerTest extends TestCase $this->assertEquals($expected, self::$customParameters); } + public function testThehandlerCanHandleTheRecordsFormattedUsingTheLineFormatter() + { + $handler = new StubNewRelicHandler(); + $handler->setFormatter(new LineFormatter()); + $handler->handle($this->getRecord(Logger::ERROR)); + } + public function testTheAppNameIsNullByDefault() { $handler = new StubNewRelicHandler(); From 5ecfbc25deed6bb7eaa408c46453356d799edd4b Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Fri, 20 May 2016 19:39:35 +0100 Subject: [PATCH 12/12] Fix issue in handling of broken iterators when serializing stack frames, fixes #772 --- src/Monolog/Formatter/JsonFormatter.php | 3 +++ src/Monolog/Formatter/NormalizerFormatter.php | 3 +++ 2 files changed, 6 insertions(+) diff --git a/src/Monolog/Formatter/JsonFormatter.php b/src/Monolog/Formatter/JsonFormatter.php index 06e9d13d..a985e2ab 100644 --- a/src/Monolog/Formatter/JsonFormatter.php +++ b/src/Monolog/Formatter/JsonFormatter.php @@ -186,6 +186,9 @@ class JsonFormatter extends NormalizerFormatter foreach ($trace as $frame) { if (isset($frame['file'])) { $data['trace'][] = $frame['file'].':'.$frame['line']; + } elseif (isset($frame['function']) && $frame['function'] === '{closure}') { + // We should again normalize the frames, because it might contain invalid items + $data['trace'][] = $frame['function']; } else { // We should again normalize the frames, because it might contain invalid items $data['trace'][] = $this->normalize($frame); diff --git a/src/Monolog/Formatter/NormalizerFormatter.php b/src/Monolog/Formatter/NormalizerFormatter.php index a76e2aed..8dec46e4 100644 --- a/src/Monolog/Formatter/NormalizerFormatter.php +++ b/src/Monolog/Formatter/NormalizerFormatter.php @@ -131,6 +131,9 @@ class NormalizerFormatter implements FormatterInterface foreach ($trace as $frame) { if (isset($frame['file'])) { $data['trace'][] = $frame['file'].':'.$frame['line']; + } elseif (isset($frame['function']) && $frame['function'] === '{closure}') { + // We should again normalize the frames, because it might contain invalid items + $data['trace'][] = $frame['function']; } else { // We should again normalize the frames, because it might contain invalid items $data['trace'][] = $this->toJson($this->normalize($frame), true);