From 0ffb4e2811a7c27ccf2ec3421acbd07293c3470d Mon Sep 17 00:00:00 2001 From: Gabriel Machado Date: Sat, 31 Aug 2019 20:17:38 -0300 Subject: [PATCH 1/4] update exception message in InsightOpsHandler --- src/Monolog/Handler/InsightOpsHandler.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Monolog/Handler/InsightOpsHandler.php b/src/Monolog/Handler/InsightOpsHandler.php index a12e3de5..8f683dce 100644 --- a/src/Monolog/Handler/InsightOpsHandler.php +++ b/src/Monolog/Handler/InsightOpsHandler.php @@ -38,7 +38,7 @@ class InsightOpsHandler extends SocketHandler public function __construct($token, $region = 'us', $useSSL = true, $level = Logger::DEBUG, $bubble = true) { if ($useSSL && !extension_loaded('openssl')) { - throw new MissingExtensionException('The OpenSSL PHP plugin is required to use SSL encrypted connection for LogEntriesHandler'); + throw new MissingExtensionException('The OpenSSL PHP plugin is required to use SSL encrypted connection for InsightOpsHandler'); } $endpoint = $useSSL From 6d76eaaf7699d6bab1609b0a5abcc9d2326ad566 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goire=20Pineau?= Date: Mon, 19 Aug 2019 17:57:34 +0200 Subject: [PATCH 2/4] Backport Interface and Trait from master to 1.X --- .php_cs | 6 ++ composer.json | 2 +- .../Handler/FormattableHandlerInterface.php | 38 ++++++++++ .../Handler/FormattableHandlerTrait.php | 62 ++++++++++++++++ .../Handler/ProcessableHandlerInterface.php | 39 ++++++++++ .../Handler/ProcessableHandlerTrait.php | 72 +++++++++++++++++++ 6 files changed, 218 insertions(+), 1 deletion(-) create mode 100644 src/Monolog/Handler/FormattableHandlerInterface.php create mode 100644 src/Monolog/Handler/FormattableHandlerTrait.php create mode 100644 src/Monolog/Handler/ProcessableHandlerInterface.php create mode 100644 src/Monolog/Handler/ProcessableHandlerTrait.php diff --git a/.php_cs b/.php_cs index 366ccd08..fe3c5bff 100644 --- a/.php_cs +++ b/.php_cs @@ -13,6 +13,12 @@ $finder = Symfony\CS\Finder::create() ->files() ->name('*.php') ->exclude('Fixtures') + // The next 4 files are here for forward compatibility, and are not used by + // Monolog itself + ->exclude(__DIR__.'src/Monolog/Handler/FormattableHandlerInterface.php') + ->exclude(__DIR__.'src/Monolog/Handler/FormattableHandlerTrait.php') + ->exclude(__DIR__.'src/Monolog/Handler/ProcessableHandlerInterface.php') + ->exclude(__DIR__.'src/Monolog/Handler/ProcessableHandlerTrait.php') ->in(__DIR__.'/src') ->in(__DIR__.'/tests') ; diff --git a/composer.json b/composer.json index 3b0c8805..097df878 100644 --- a/composer.json +++ b/composer.json @@ -59,7 +59,7 @@ }, "scripts": { "test": [ - "parallel-lint . --exclude vendor", + "parallel-lint . --exclude vendor --exclude src/Monolog/Handler/FormattableHandlerInterface.php --exclude src/Monolog/Handler/FormattableHandlerTrait.php --exclude src/Monolog/Handler/ProcessableHandlerInterface.php --exclude src/Monolog/Handler/ProcessableHandlerTrait.php", "phpunit" ] } diff --git a/src/Monolog/Handler/FormattableHandlerInterface.php b/src/Monolog/Handler/FormattableHandlerInterface.php new file mode 100644 index 00000000..b6d4c6ac --- /dev/null +++ b/src/Monolog/Handler/FormattableHandlerInterface.php @@ -0,0 +1,38 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Monolog\Handler; + +use Monolog\Formatter\FormatterInterface; + +/** + * Interface to describe loggers that have a formatter + * + * @internal This interface is present in monolog 1.x to ease forward compatibility. + * @author Jordi Boggiano + */ +interface FormattableHandlerInterface +{ + /** + * Sets the formatter. + * + * @param FormatterInterface $formatter + * @return HandlerInterface self + */ + public function setFormatter(FormatterInterface $formatter): HandlerInterface; + + /** + * Gets the formatter. + * + * @return FormatterInterface + */ + public function getFormatter(): FormatterInterface; +} diff --git a/src/Monolog/Handler/FormattableHandlerTrait.php b/src/Monolog/Handler/FormattableHandlerTrait.php new file mode 100644 index 00000000..5233bf55 --- /dev/null +++ b/src/Monolog/Handler/FormattableHandlerTrait.php @@ -0,0 +1,62 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Monolog\Handler; + +use Monolog\Formatter\FormatterInterface; +use Monolog\Formatter\LineFormatter; + +/** + * Helper trait for implementing FormattableInterface + * + * @internal This interface is present in monolog 1.x to ease forward compatibility. + * @author Jordi Boggiano + */ +trait FormattableHandlerTrait +{ + /** + * @var FormatterInterface + */ + protected $formatter; + + /** + * {@inheritdoc} + * @suppress PhanTypeMismatchReturn + */ + public function setFormatter(FormatterInterface $formatter): HandlerInterface + { + $this->formatter = $formatter; + + return $this; + } + + /** + * {@inheritdoc} + */ + public function getFormatter(): FormatterInterface + { + if (!$this->formatter) { + $this->formatter = $this->getDefaultFormatter(); + } + + return $this->formatter; + } + + /** + * Gets the default formatter. + * + * Overwrite this if the LineFormatter is not a good default for your handler. + */ + protected function getDefaultFormatter(): FormatterInterface + { + return new LineFormatter(); + } +} diff --git a/src/Monolog/Handler/ProcessableHandlerInterface.php b/src/Monolog/Handler/ProcessableHandlerInterface.php new file mode 100644 index 00000000..bfa71497 --- /dev/null +++ b/src/Monolog/Handler/ProcessableHandlerInterface.php @@ -0,0 +1,39 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Monolog\Handler; + +use Monolog\Processor\ProcessorInterface; + +/** + * Interface to describe loggers that have processors + * + * @internal This interface is present in monolog 1.x to ease forward compatibility. + * @author Jordi Boggiano + */ +interface ProcessableHandlerInterface +{ + /** + * Adds a processor in the stack. + * + * @param ProcessorInterface|callable $callback + * @return HandlerInterface self + */ + public function pushProcessor(callable $callback): HandlerInterface; + + /** + * Removes the processor on top of the stack and returns it. + * + * @throws \LogicException In case the processor stack is empty + * @return callable + */ + public function popProcessor(): callable; +} diff --git a/src/Monolog/Handler/ProcessableHandlerTrait.php b/src/Monolog/Handler/ProcessableHandlerTrait.php new file mode 100644 index 00000000..a5092929 --- /dev/null +++ b/src/Monolog/Handler/ProcessableHandlerTrait.php @@ -0,0 +1,72 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Monolog\Handler; + +use Monolog\ResettableInterface; + +/** + * Helper trait for implementing ProcessableInterface + * + * @internal This interface is present in monolog 1.x to ease forward compatibility. + * @author Jordi Boggiano + */ +trait ProcessableHandlerTrait +{ + /** + * @var callable[] + */ + protected $processors = []; + + /** + * {@inheritdoc} + * @suppress PhanTypeMismatchReturn + */ + public function pushProcessor(callable $callback): HandlerInterface + { + array_unshift($this->processors, $callback); + + return $this; + } + + /** + * {@inheritdoc} + */ + public function popProcessor(): callable + { + if (!$this->processors) { + throw new \LogicException('You tried to pop from an empty processor stack.'); + } + + return array_shift($this->processors); + } + + /** + * Processes a record. + */ + protected function processRecord(array $record): array + { + foreach ($this->processors as $processor) { + $record = $processor($record); + } + + return $record; + } + + protected function resetProcessors(): void + { + foreach ($this->processors as $processor) { + if ($processor instanceof ResettableInterface) { + $processor->reset(); + } + } + } +} From c8b0d08cebfaee16569b0e5a9a80911cc238fe1d Mon Sep 17 00:00:00 2001 From: Pierre Lannoy Date: Thu, 5 Sep 2019 13:28:42 +0200 Subject: [PATCH 3/4] Change chrome header size limit Due to change in chromium header size support, the size limit enforced by the handler must be decreased. --- src/Monolog/Handler/ChromePHPHandler.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Monolog/Handler/ChromePHPHandler.php b/src/Monolog/Handler/ChromePHPHandler.php index 37419a06..ac98d5de 100644 --- a/src/Monolog/Handler/ChromePHPHandler.php +++ b/src/Monolog/Handler/ChromePHPHandler.php @@ -43,7 +43,7 @@ class ChromePHPHandler extends AbstractProcessingHandler /** * Tracks whether we sent too much data * - * Chrome limits the headers to 256KB, so when we sent 240KB we stop sending + * Chrome limits the headers to 4KB, so when we sent 3KB we stop sending * * @var bool */ @@ -136,7 +136,7 @@ class ChromePHPHandler extends AbstractProcessingHandler $json = @json_encode(self::$json); $data = base64_encode(utf8_encode($json)); - if (strlen($data) > 240 * 1024) { + if (strlen($data) > 3 * 1024) { self::$overflowed = true; $record = array( From 190aa65aac9062072baaac39a079c6dbdc4feb8d Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Thu, 5 Sep 2019 14:33:55 +0200 Subject: [PATCH 4/4] Fix chromephp tests --- tests/Monolog/Handler/ChromePHPHandlerTest.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/Monolog/Handler/ChromePHPHandlerTest.php b/tests/Monolog/Handler/ChromePHPHandlerTest.php index 421cc491..bb1b0792 100644 --- a/tests/Monolog/Handler/ChromePHPHandlerTest.php +++ b/tests/Monolog/Handler/ChromePHPHandlerTest.php @@ -66,10 +66,10 @@ class ChromePHPHandlerTest extends TestCase { $handler = new TestChromePHPHandler(); $handler->handle($this->getRecord(Logger::DEBUG)); - $handler->handle($this->getRecord(Logger::WARNING, str_repeat('a', 150 * 1024))); + $handler->handle($this->getRecord(Logger::WARNING, str_repeat('a', 2 * 1024))); // overflow chrome headers limit - $handler->handle($this->getRecord(Logger::WARNING, str_repeat('a', 100 * 1024))); + $handler->handle($this->getRecord(Logger::WARNING, str_repeat('b', 2 * 1024))); $expected = array( 'X-ChromeLogger-Data' => base64_encode(utf8_encode(json_encode(array( @@ -84,7 +84,7 @@ class ChromePHPHandlerTest extends TestCase ), array( 'test', - str_repeat('a', 150 * 1024), + str_repeat('a', 2 * 1024), 'unknown', 'warn', ),