From ff43ef98603c23b198e658ba192053be243f66db Mon Sep 17 00:00:00 2001 From: Artur Geraschenko Date: Thu, 12 Dec 2013 21:27:31 +0300 Subject: [PATCH 01/30] Init IntrospectionProcessor with skip classes parameter with fixed array notation Logger maybe use in other debug classes and I must be able to skip my debug classes. For example: new IntrospectionProcessor(Logger::DEBUG, array('Monolog\\', 'Debug')) --- .../Processor/IntrospectionProcessor.php | 21 +++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/src/Monolog/Processor/IntrospectionProcessor.php b/src/Monolog/Processor/IntrospectionProcessor.php index a7de5d8d..26007aa8 100644 --- a/src/Monolog/Processor/IntrospectionProcessor.php +++ b/src/Monolog/Processor/IntrospectionProcessor.php @@ -28,9 +28,12 @@ class IntrospectionProcessor { private $level; - public function __construct($level = Logger::DEBUG) + private $skipClassesPartials; + + public function __construct($level = Logger::DEBUG, array $skipClassesPartials = array('Monolog\\')) { $this->level = $level; + $this->skipClassesPartials = $skipClassesPartials; } /** @@ -52,9 +55,19 @@ class IntrospectionProcessor array_shift($trace); $i = 0; - while (isset($trace[$i]['class']) && false !== strpos($trace[$i]['class'], 'Monolog\\')) { - $i++; - } + + while (isset($trace[$i]['class'])) + { + foreach ($this->skipClassesPartials as $part) + { + if (strpos($trace[$i]['class'], $part) !== false) + { + $i++; + continue 2; + } + } + break; + } // we should have the call source now $record['extra'] = array_merge( From a35326e406b76d95833afd62b745f3ee3cce2e90 Mon Sep 17 00:00:00 2001 From: Benjamin Zikarsky Date: Wed, 18 Dec 2013 21:27:50 +0100 Subject: [PATCH 02/30] Fixes MongoDBHandler unit-test On systems with mongo-ext but no MongoDB on localhost the unit- tests are failing. This commit disables the constructor execution for the Mongo-mock, so no connection-error is generated. --- tests/Monolog/Handler/MongoDBHandlerTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Monolog/Handler/MongoDBHandlerTest.php b/tests/Monolog/Handler/MongoDBHandlerTest.php index ce3433e1..7f06d666 100644 --- a/tests/Monolog/Handler/MongoDBHandlerTest.php +++ b/tests/Monolog/Handler/MongoDBHandlerTest.php @@ -26,7 +26,7 @@ class MongoDBHandlerTest extends TestCase public function testHandle() { - $mongo = $this->getMock('Mongo', array('selectCollection')); + $mongo = $this->getMock('Mongo', array('selectCollection'), array(), '', false); $collection = $this->getMock('stdClass', array('save')); $mongo->expects($this->once()) From 67a908796b4f1aa48e2deca96174c8cd04c8776f Mon Sep 17 00:00:00 2001 From: Milos Levacic Date: Tue, 24 Dec 2013 21:15:02 +0100 Subject: [PATCH 03/30] Add name length check to the HipChatHandler As explained in its docblock, the validation function will fall back to a simple strlen check if mb_strlen is not available. However, that very specific case is not one that was deemed important to support, as anyone using UTF-8 in their code, without having mbstring available will probably have bigger problems to worry about. Fixes #289 --- src/Monolog/Handler/HipChatHandler.php | 31 ++++++++++++++++++++ tests/Monolog/Handler/HipChatHandlerTest.php | 8 +++++ 2 files changed, 39 insertions(+) diff --git a/src/Monolog/Handler/HipChatHandler.php b/src/Monolog/Handler/HipChatHandler.php index 6df3f06d..5a6a46b0 100644 --- a/src/Monolog/Handler/HipChatHandler.php +++ b/src/Monolog/Handler/HipChatHandler.php @@ -27,6 +27,11 @@ use Monolog\Logger; */ class HipChatHandler extends SocketHandler { + /** + * The maximum allowed length for the name used in the "from" field. + */ + const MAXIMUM_NAME_LENGTH = 15; + /** * @var string */ @@ -58,6 +63,10 @@ class HipChatHandler extends SocketHandler */ public function __construct($token, $room, $name = 'Monolog', $notify = false, $level = Logger::CRITICAL, $bubble = true, $useSSL = true) { + if (!$this->validateName($name)) { + throw new \InvalidArgumentException('The supplied name is too long. HipChat\'s v1 API supports names up to 15 UTF-8 characters.'); + } + $connectionString = $useSSL ? 'ssl://api.hipchat.com:443' : 'api.hipchat.com:80'; parent::__construct($connectionString, $level, $bubble); @@ -216,4 +225,26 @@ class HipChatHandler extends SocketHandler return $batchRecord; } + + /** + * Validates the supplied name for the "from" field. + * + * If the `mb_strlen()` function is available, it will use that, as HipChat + * allows UTF-8 characters. Otherwise, it will fall back to `strlen()`. + * + * Note that this might cause false failures in the specific case of using + * a valid name with less than 16 characters, but 16 or more bytes, on a + * system where `mb_strlen()` is unavailable. + * + * @param string $name Name to validate + * @return Boolean + */ + private function validateName($name) + { + if (function_exists('mb_strlen')) { + return (mb_strlen($name) <= static::MAXIMUM_NAME_LENGTH); + } + + return (strlen($name) <= static::MAXIMUM_NAME_LENGTH); + } } diff --git a/tests/Monolog/Handler/HipChatHandlerTest.php b/tests/Monolog/Handler/HipChatHandlerTest.php index fcbc02f0..8b9e4d44 100644 --- a/tests/Monolog/Handler/HipChatHandlerTest.php +++ b/tests/Monolog/Handler/HipChatHandlerTest.php @@ -156,4 +156,12 @@ class HipChatHandlerTest extends TestCase $this->handler->setFormatter($this->getIdentityFormatter()); } + + /** + * @expectedException InvalidArgumentException + */ + public function testCreateWithTooLongName() + { + $hipChatHandler = new \Monolog\Handler\HipChatHandler('token', 'room', 'SixteenCharsHere'); + } } From 56f17118c9c949753695c8d0c8ff59c542ea5b5d Mon Sep 17 00:00:00 2001 From: Markus Staab Date: Wed, 25 Dec 2013 23:56:26 +0100 Subject: [PATCH 04/30] Added hhvm to travis.yml --- .travis.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.travis.yml b/.travis.yml index 7175df11..04e2e7ba 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,6 +5,11 @@ php: - 5.3 - 5.4 - 5.5 + - hhvm + +matrix: + allow_failures: + - php: hhvm before_script: - composer install --dev --prefer-source From 52449910640a80a8b47acb5ed710b829eb9aac4e Mon Sep 17 00:00:00 2001 From: Markus Staab Date: Wed, 25 Dec 2013 23:58:29 +0100 Subject: [PATCH 05/30] Updated to latest stable version --- doc/usage.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/usage.md b/doc/usage.md index 0312e90c..846bd51a 100644 --- a/doc/usage.md +++ b/doc/usage.md @@ -8,7 +8,7 @@ Monolog is available on Packagist ([monolog/monolog](http://packagist.org/packag and as such installable via [Composer](http://getcomposer.org/). ```bash -php composer.phar require monolog/monolog '~1.4' +php composer.phar require monolog/monolog '~1.7' ``` If you do not use Composer, you can grab the code from GitHub, and use any From 22642bc8a7e5a2a18aeae62631b8de831f4ee6f4 Mon Sep 17 00:00:00 2001 From: Markus Staab Date: Thu, 26 Dec 2013 00:12:49 +0100 Subject: [PATCH 06/30] Fixed syntax error in sample code --- doc/extending.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/extending.md b/doc/extending.md index fcd7af2b..bb39ddcf 100644 --- a/doc/extending.md +++ b/doc/extending.md @@ -65,7 +65,7 @@ You can now use this handler in your logger: ```php pushHandler(new PDOHandler(new PDO('sqlite:logs.sqlite')); +$logger->pushHandler(new PDOHandler(new PDO('sqlite:logs.sqlite'))); // You can now use your logger $logger->addInfo('My logger is now ready'); From 9e536cfabae867f62f592ae51b841a461d9ef664 Mon Sep 17 00:00:00 2001 From: Markus Staab Date: Thu, 26 Dec 2013 00:18:20 +0100 Subject: [PATCH 07/30] fix phpdoc --- src/Monolog/Registry.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Monolog/Registry.php b/src/Monolog/Registry.php index 03cd3eaa..a3eba079 100644 --- a/src/Monolog/Registry.php +++ b/src/Monolog/Registry.php @@ -48,7 +48,7 @@ class Registry * Adds new logging channel to the registry * * @param Logger $logger Instance of the logging channel - * @param string $name Name of the logging channel ($logger->getName() by default) + * @param string|null $name Name of the logging channel ($logger->getName() by default) * @param boolean $overwrite Overwrite instance in the registry if the given name already exists? * @throws \InvalidArgumentException If $overwrite set to false and named Logger instance already exists */ From 100a1b01f268a606ab0062b432fc6a315d228f21 Mon Sep 17 00:00:00 2001 From: Markus Staab Date: Thu, 26 Dec 2013 00:25:22 +0100 Subject: [PATCH 08/30] Minor phpdoc fixes --- src/Monolog/Logger.php | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/Monolog/Logger.php b/src/Monolog/Logger.php index 087dee2f..33b22367 100644 --- a/src/Monolog/Logger.php +++ b/src/Monolog/Logger.php @@ -107,12 +107,15 @@ class Logger implements LoggerInterface */ protected static $timezone; + /** + * @var string + */ protected $name; /** * The handler stack * - * @var array of Monolog\Handler\HandlerInterface + * @var HandlerInterface[] */ protected $handlers; @@ -121,14 +124,14 @@ class Logger implements LoggerInterface * * To process records of a single handler instead, add the processor on that specific handler * - * @var array of callables + * @var callable[] */ protected $processors; /** - * @param string $name The logging channel - * @param array $handlers Optional stack of handlers, the first one in the array is called first, etc. - * @param array $processors Optional array of processors + * @param string $name The logging channel + * @param HandlerInterface[] $handlers Optional stack of handlers, the first one in the array is called first, etc. + * @param callable[] $processors Optional array of processors */ public function __construct($name, array $handlers = array(), array $processors = array()) { From 3926d95f8a7270ef81c28f346100c297d03ada5d Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Thu, 26 Dec 2013 11:43:12 +0100 Subject: [PATCH 09/30] CS fixes --- src/Monolog/Handler/AbstractHandler.php | 4 +-- src/Monolog/Handler/CubeHandler.php | 4 +-- src/Monolog/Handler/DynamoDbHandler.php | 2 +- src/Monolog/Handler/HandlerInterface.php | 2 +- src/Monolog/Handler/PushoverHandler.php | 26 +++++++++---------- src/Monolog/Handler/RavenHandler.php | 4 +-- src/Monolog/Handler/RotatingFileHandler.php | 2 +- src/Monolog/Logger.php | 6 ++--- .../Processor/IntrospectionProcessor.php | 13 ++++------ 9 files changed, 30 insertions(+), 33 deletions(-) diff --git a/src/Monolog/Handler/AbstractHandler.php b/src/Monolog/Handler/AbstractHandler.php index 81fc7a37..3bb21b71 100644 --- a/src/Monolog/Handler/AbstractHandler.php +++ b/src/Monolog/Handler/AbstractHandler.php @@ -141,8 +141,8 @@ abstract class AbstractHandler implements HandlerInterface /** * Sets the bubbling behavior. * - * @param Boolean $bubble true means that this handler allows bubbling. - * false means that bubbling is not permitted. + * @param Boolean $bubble true means that this handler allows bubbling. + * false means that bubbling is not permitted. * @return self */ public function setBubble($bubble) diff --git a/src/Monolog/Handler/CubeHandler.php b/src/Monolog/Handler/CubeHandler.php index cdcde2d5..d968720c 100644 --- a/src/Monolog/Handler/CubeHandler.php +++ b/src/Monolog/Handler/CubeHandler.php @@ -32,8 +32,8 @@ class CubeHandler extends AbstractProcessingHandler * Create a Cube handler * * @throws UnexpectedValueException when given url is not a valid url. - * A valid url must consists of three parts : protocol://host:port - * Only valid protocol used by Cube are http and udp + * A valid url must consists of three parts : protocol://host:port + * Only valid protocol used by Cube are http and udp */ public function __construct($url, $level = Logger::DEBUG, $bubble = true) { diff --git a/src/Monolog/Handler/DynamoDbHandler.php b/src/Monolog/Handler/DynamoDbHandler.php index ad6622e1..5702c5fb 100644 --- a/src/Monolog/Handler/DynamoDbHandler.php +++ b/src/Monolog/Handler/DynamoDbHandler.php @@ -75,7 +75,7 @@ class DynamoDbHandler extends AbstractProcessingHandler */ protected function filterEmptyFields(array $record) { - return array_filter($record, function($value) { + return array_filter($record, function ($value) { return !empty($value) || false === $value || 0 === $value; }); } diff --git a/src/Monolog/Handler/HandlerInterface.php b/src/Monolog/Handler/HandlerInterface.php index 4e7d6392..accff037 100644 --- a/src/Monolog/Handler/HandlerInterface.php +++ b/src/Monolog/Handler/HandlerInterface.php @@ -47,7 +47,7 @@ interface HandlerInterface * * @param array $record The record to handle * @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. */ public function handle(array $record); diff --git a/src/Monolog/Handler/PushoverHandler.php b/src/Monolog/Handler/PushoverHandler.php index 9408a031..b1dff9b6 100644 --- a/src/Monolog/Handler/PushoverHandler.php +++ b/src/Monolog/Handler/PushoverHandler.php @@ -32,19 +32,19 @@ class PushoverHandler extends SocketHandler private $emergencyLevel; /** - * @param string $token Pushover api token - * @param string|array $users Pushover user id or array of ids the message will be sent to - * @param string $title Title sent to the Pushover API - * @param integer $level The minimum logging level at which this handler will be triggered - * @param Boolean $bubble Whether the messages that are handled can bubble up the stack or not - * @param Boolean $useSSL Whether to connect via SSL. Required when pushing messages to users that are not - * the pushover.net app owner. OpenSSL is required for this option. - * @param integer $highPriorityLevel The minimum logging level at which this handler will start - * sending "high priority" requests to the Pushover API - * @param integer $emergencyLevel The minimum logging level at which this handler will start - * sending "emergency" requests to the Pushover API - * @param integer $retry The retry parameter specifies how often (in seconds) the Pushover servers will send the same notification to the user. - * @param integer $expire The expire parameter specifies how many seconds your notification will continue to be retried for (every retry seconds). + * @param string $token Pushover api token + * @param string|array $users Pushover user id or array of ids the message will be sent to + * @param string $title Title sent to the Pushover API + * @param integer $level The minimum logging level at which this handler will be triggered + * @param Boolean $bubble Whether the messages that are handled can bubble up the stack or not + * @param Boolean $useSSL Whether to connect via SSL. Required when pushing messages to users that are not + * the pushover.net app owner. OpenSSL is required for this option. + * @param integer $highPriorityLevel The minimum logging level at which this handler will start + * sending "high priority" requests to the Pushover API + * @param integer $emergencyLevel The minimum logging level at which this handler will start + * sending "emergency" requests to the Pushover API + * @param integer $retry The retry parameter specifies how often (in seconds) the Pushover servers will send the same notification to the user. + * @param integer $expire The expire parameter specifies how many seconds your notification will continue to be retried for (every retry seconds). */ public function __construct($token, $users, $title = null, $level = Logger::CRITICAL, $bubble = true, $useSSL = true, $highPriorityLevel = Logger::CRITICAL, $emergencyLevel = Logger::EMERGENCY, $retry = 30, $expire = 25200) { diff --git a/src/Monolog/Handler/RavenHandler.php b/src/Monolog/Handler/RavenHandler.php index 02c8261e..653e61c1 100644 --- a/src/Monolog/Handler/RavenHandler.php +++ b/src/Monolog/Handler/RavenHandler.php @@ -69,7 +69,7 @@ class RavenHandler extends AbstractProcessingHandler $level = $this->level; // filter records based on their level - $records = array_filter($records, function($record) use ($level) { + $records = array_filter($records, function ($record) use ($level) { return $record['level'] >= $level; }); @@ -78,7 +78,7 @@ class RavenHandler extends AbstractProcessingHandler } // the record with the highest severity is the "main" one - $record = array_reduce($records, function($highest, $record) { + $record = array_reduce($records, function ($highest, $record) { if ($record['level'] >= $highest['level']) { return $record; } diff --git a/src/Monolog/Handler/RotatingFileHandler.php b/src/Monolog/Handler/RotatingFileHandler.php index 18a0fcc5..a02ff516 100644 --- a/src/Monolog/Handler/RotatingFileHandler.php +++ b/src/Monolog/Handler/RotatingFileHandler.php @@ -105,7 +105,7 @@ class RotatingFileHandler extends StreamHandler } // Sorting the files by name to remove the older ones - usort($logFiles, function($a, $b) { + usort($logFiles, function ($a, $b) { return strcmp($b, $a); }); diff --git a/src/Monolog/Logger.php b/src/Monolog/Logger.php index 33b22367..82a22291 100644 --- a/src/Monolog/Logger.php +++ b/src/Monolog/Logger.php @@ -129,9 +129,9 @@ class Logger implements LoggerInterface protected $processors; /** - * @param string $name The logging channel - * @param HandlerInterface[] $handlers Optional stack of handlers, the first one in the array is called first, etc. - * @param callable[] $processors Optional array of processors + * @param string $name The logging channel + * @param HandlerInterface[] $handlers Optional stack of handlers, the first one in the array is called first, etc. + * @param callable[] $processors Optional array of processors */ public function __construct($name, array $handlers = array(), array $processors = array()) { diff --git a/src/Monolog/Processor/IntrospectionProcessor.php b/src/Monolog/Processor/IntrospectionProcessor.php index 26007aa8..a2c48ce6 100644 --- a/src/Monolog/Processor/IntrospectionProcessor.php +++ b/src/Monolog/Processor/IntrospectionProcessor.php @@ -30,7 +30,7 @@ class IntrospectionProcessor private $skipClassesPartials; - public function __construct($level = Logger::DEBUG, array $skipClassesPartials = array('Monolog\\')) + public function __construct($level = Logger::DEBUG, array $skipClassesPartials = array('Monolog\\')) { $this->level = $level; $this->skipClassesPartials = $skipClassesPartials; @@ -56,18 +56,15 @@ class IntrospectionProcessor $i = 0; - while (isset($trace[$i]['class'])) - { - foreach ($this->skipClassesPartials as $part) - { - if (strpos($trace[$i]['class'], $part) !== false) - { + while (isset($trace[$i]['class'])) { + foreach ($this->skipClassesPartials as $part) { + if (strpos($trace[$i]['class'], $part) !== false) { $i++; continue 2; } } break; - } + } // we should have the call source now $record['extra'] = array_merge( From d4cb2c49f4ab5aed35cffa2537ca9c641a692fc1 Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Thu, 26 Dec 2013 11:50:12 +0100 Subject: [PATCH 10/30] Fix test on windows --- tests/Monolog/Handler/SyslogUdpHandlerTest.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/Monolog/Handler/SyslogUdpHandlerTest.php b/tests/Monolog/Handler/SyslogUdpHandlerTest.php index fcf9307a..1cc2148a 100644 --- a/tests/Monolog/Handler/SyslogUdpHandlerTest.php +++ b/tests/Monolog/Handler/SyslogUdpHandlerTest.php @@ -16,16 +16,16 @@ class SyslogUdpHandlerTest extends \PHPUnit_Framework_TestCase public function testWeSplitIntoLines() { - $handler = new SyslogUdpHandler("127.0.0.1", 514, "local5"); + $handler = new SyslogUdpHandler("127.0.0.1", 514, "authpriv"); $handler->setFormatter(new \Monolog\Formatter\ChromePHPFormatter()); $socket = $this->getMock('\Monolog\Handler\SyslogUdp\UdpSocket', array('write'), array('lol', 'lol')); $socket->expects($this->at(0)) ->method('write') - ->with("lol", "<172>: "); + ->with("lol", "<".(LOG_AUTHPRIV + LOG_WARNING).">: "); $socket->expects($this->at(1)) ->method('write') - ->with("hej", "<172>: "); + ->with("hej", "<".(LOG_AUTHPRIV + LOG_WARNING).">: "); $handler->setSocket($socket); From edb4aaa75fb160e9b9987550ddfde79361838ea5 Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Thu, 26 Dec 2013 11:58:24 +0100 Subject: [PATCH 11/30] Add exts --- .travis.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.travis.yml b/.travis.yml index 04e2e7ba..023d5910 100644 --- a/.travis.yml +++ b/.travis.yml @@ -12,6 +12,8 @@ matrix: - php: hhvm before_script: + - echo "extension = mongo.so" >> ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini + - echo "extension = amqp.so" >> ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini - composer install --dev --prefer-source script: ./vendor/bin/phpunit From ad77932a7b9a14f1a6e93648c6d4d5b96515588f Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Thu, 26 Dec 2013 12:16:07 +0100 Subject: [PATCH 12/30] Update amqp test mock --- tests/Monolog/Handler/AmqpExchangeMock.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/Monolog/Handler/AmqpExchangeMock.php b/tests/Monolog/Handler/AmqpExchangeMock.php index 3415c82c..20594c23 100644 --- a/tests/Monolog/Handler/AmqpExchangeMock.php +++ b/tests/Monolog/Handler/AmqpExchangeMock.php @@ -19,9 +19,9 @@ class AmqpExchangeMock extends \AMQPExchange { } - public function publish($message, $routing_key, $params = 0, $attributes = array()) + public function publish($message, $routing_key, $flags = 0, array $attributes = array()) { - $this->messages[] = array($message, $routing_key, $params, $attributes); + $this->messages[] = array($message, $routing_key, $flags, $attributes); return true; } From b265bbd70dbe7386578d19101421213aa5ce7714 Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Thu, 26 Dec 2013 14:11:00 +0100 Subject: [PATCH 13/30] Fix signature --- tests/Monolog/Handler/AmqpExchangeMock.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Monolog/Handler/AmqpExchangeMock.php b/tests/Monolog/Handler/AmqpExchangeMock.php index 20594c23..1fe53f8a 100644 --- a/tests/Monolog/Handler/AmqpExchangeMock.php +++ b/tests/Monolog/Handler/AmqpExchangeMock.php @@ -19,7 +19,7 @@ class AmqpExchangeMock extends \AMQPExchange { } - public function publish($message, $routing_key, $flags = 0, array $attributes = array()) + public function publish($message, $routing_key, $flags = AMQP_NOPARAM, array $attributes = array()) { $this->messages[] = array($message, $routing_key, $flags, $attributes); From e92cb54c24e990c505be1b4af82e962d55d092df Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Thu, 26 Dec 2013 14:24:17 +0100 Subject: [PATCH 14/30] Do away with this horrible mock class --- tests/Monolog/Handler/AmqpExchangeMock.php | 38 ---------------------- tests/Monolog/Handler/AmqpHandlerTest.php | 20 ++++++++---- 2 files changed, 13 insertions(+), 45 deletions(-) delete mode 100644 tests/Monolog/Handler/AmqpExchangeMock.php diff --git a/tests/Monolog/Handler/AmqpExchangeMock.php b/tests/Monolog/Handler/AmqpExchangeMock.php deleted file mode 100644 index 1fe53f8a..00000000 --- a/tests/Monolog/Handler/AmqpExchangeMock.php +++ /dev/null @@ -1,38 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Monolog\Handler; - -class AmqpExchangeMock extends \AMQPExchange -{ - protected $messages = array(); - - public function __construct() - { - } - - public function publish($message, $routing_key, $flags = AMQP_NOPARAM, array $attributes = array()) - { - $this->messages[] = array($message, $routing_key, $flags, $attributes); - - return true; - } - - public function getMessages() - { - return $this->messages; - } - - public function setName($name) - { - return true; - } -} diff --git a/tests/Monolog/Handler/AmqpHandlerTest.php b/tests/Monolog/Handler/AmqpHandlerTest.php index 73690916..249f2b72 100644 --- a/tests/Monolog/Handler/AmqpHandlerTest.php +++ b/tests/Monolog/Handler/AmqpHandlerTest.php @@ -32,7 +32,19 @@ class AmqpHandlerTest extends TestCase public function testHandle() { - $exchange = $this->getExchange(); + $messages = array(); + + $exchange = $this->getMock('AMQPExchange', array('publish', 'setName'), array(), '', false); + $exchange->expects($this->once()) + ->method('setName') + ->with('log') + ; + $exchange->expects($this->any()) + ->method('publish') + ->will($this->returnCallback(function ($message, $routing_key, $flags = 0, $attributes = array()) use (&$messages) { + $messages[] = array($message, $routing_key, $flags, $attributes); + })) + ; $handler = new AmqpHandler($exchange, 'log'); @@ -60,15 +72,9 @@ class AmqpHandlerTest extends TestCase $handler->handle($record); - $messages = $exchange->getMessages(); $this->assertCount(1, $messages); $messages[0][0] = json_decode($messages[0][0], true); unset($messages[0][0]['datetime']); $this->assertEquals($expected, $messages[0]); } - - protected function getExchange() - { - return new AmqpExchangeMock(); - } } From 9125a3f977273d92603b9a789c7e43f2cf9bac72 Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Wed, 1 Jan 2014 19:18:15 +0100 Subject: [PATCH 15/30] Set default timezone to avoid tripping up hhvm --- tests/bootstrap.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/bootstrap.php b/tests/bootstrap.php index 496c3880..05e49eda 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -11,3 +11,5 @@ $loader = require __DIR__ . "/../vendor/autoload.php"; $loader->add('Monolog\\', __DIR__); + +date_default_timezone_set('UTC'); From 9bfd2230cf64ca66145ec12f47bdc911b57dc21b Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Wed, 1 Jan 2014 19:20:42 +0100 Subject: [PATCH 16/30] Attempt to fix hhvm build --- .travis.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index 023d5910..f36bcd36 100644 --- a/.travis.yml +++ b/.travis.yml @@ -12,8 +12,8 @@ matrix: - php: hhvm before_script: - - echo "extension = mongo.so" >> ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini - - echo "extension = amqp.so" >> ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini - - composer install --dev --prefer-source + - if [ "`phpenv version-name`" != "" ]; then echo "extension = mongo.so" >> ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini; fi + - if [ "`phpenv version-name`" != "" ]; then echo "extension = amqp.so" >> ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini; fi + - composer install --prefer-source script: ./vendor/bin/phpunit From a1e98f4e1da5b0235a74d11dcf7cdb2692b28ffc Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Wed, 1 Jan 2014 19:24:16 +0100 Subject: [PATCH 17/30] Attempt to fix hhvm build, take 2 --- .travis.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index f36bcd36..e01d4372 100644 --- a/.travis.yml +++ b/.travis.yml @@ -12,8 +12,8 @@ matrix: - php: hhvm before_script: - - if [ "`phpenv version-name`" != "" ]; then echo "extension = mongo.so" >> ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini; fi - - if [ "`phpenv version-name`" != "" ]; then echo "extension = amqp.so" >> ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini; fi + - if [ "`phpenv version-name`" != "hhvm" ]; then echo "extension = mongo.so" >> ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini; fi + - if [ "`phpenv version-name`" != "hhvm" ]; then echo "extension = amqp.so" >> ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini; fi - composer install --prefer-source script: ./vendor/bin/phpunit From b17c7a41d16fc23f9e2b8bfb637dd0f1e620fe17 Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Thu, 9 Jan 2014 23:27:36 +0100 Subject: [PATCH 18/30] Attempt hhvm build fix --- tests/Monolog/Handler/DynamoDbHandlerTest.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/Monolog/Handler/DynamoDbHandlerTest.php b/tests/Monolog/Handler/DynamoDbHandlerTest.php index 21f0f16c..a38a8cb7 100644 --- a/tests/Monolog/Handler/DynamoDbHandlerTest.php +++ b/tests/Monolog/Handler/DynamoDbHandlerTest.php @@ -21,7 +21,9 @@ class DynamoDbHandlerTest extends TestCase $this->markTestSkipped('aws/aws-sdk-php not installed'); } - $this->client = $this->getMockBuilder('Aws\DynamoDb\DynamoDbClient')->disableOriginalConstructor()->getMock(); + $this->client = $this->getMockBuilder('Aws\DynamoDb\DynamoDbClient') + ->setMethods(array('formatAttributes', '__call')) + ->disableOriginalConstructor()->getMock(); } public function testConstruct() From d81ca5a8d2d97bf9d77605359a12399c0ca28653 Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Fri, 10 Jan 2014 09:22:47 +0100 Subject: [PATCH 19/30] Promote hhvm to full support --- .travis.yml | 4 ---- 1 file changed, 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index e01d4372..d0d1b27e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -7,10 +7,6 @@ php: - 5.5 - hhvm -matrix: - allow_failures: - - php: hhvm - before_script: - if [ "`phpenv version-name`" != "hhvm" ]; then echo "extension = mongo.so" >> ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini; fi - if [ "`phpenv version-name`" != "hhvm" ]; then echo "extension = amqp.so" >> ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini; fi From 3f5fd1dabc5a703a492a36c60c7cacff71ca46ca Mon Sep 17 00:00:00 2001 From: adlawson Date: Tue, 14 Jan 2014 12:56:38 +0000 Subject: [PATCH 20/30] Remove unnecessary `use` statement --- src/Monolog/Formatter/ScalarFormatter.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/Monolog/Formatter/ScalarFormatter.php b/src/Monolog/Formatter/ScalarFormatter.php index 9e4201ab..5d345d53 100644 --- a/src/Monolog/Formatter/ScalarFormatter.php +++ b/src/Monolog/Formatter/ScalarFormatter.php @@ -11,8 +11,6 @@ namespace Monolog\Formatter; -use Monolog\Formatter\NormalizerFormatter; - /** * Formats data into an associative array of scalar values. * Objects and arrays will be JSON encoded. From fab4ec2c12b0260bc1f71f0068be09022a944f05 Mon Sep 17 00:00:00 2001 From: Michael Grinko Date: Wed, 15 Jan 2014 11:01:53 +0200 Subject: [PATCH 21/30] [minor] Indent was fixed --- src/Monolog/Logger.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Monolog/Logger.php b/src/Monolog/Logger.php index 82a22291..4a74db35 100644 --- a/src/Monolog/Logger.php +++ b/src/Monolog/Logger.php @@ -344,7 +344,7 @@ class Logger implements LoggerInterface */ public function addEmergency($message, array $context = array()) { - return $this->addRecord(static::EMERGENCY, $message, $context); + return $this->addRecord(static::EMERGENCY, $message, $context); } /** From 1472e65b4cbd63c5aa611127887bde292309f766 Mon Sep 17 00:00:00 2001 From: Christian Flothmann Date: Fri, 17 Jan 2014 14:35:55 +0100 Subject: [PATCH 22/30] do not bind the raven version to 0.5*, use possible newer versions --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 0939dd49..9b153194 100644 --- a/composer.json +++ b/composer.json @@ -19,7 +19,7 @@ "require-dev": { "phpunit/phpunit": "~3.7.0", "mlehner/gelf-php": "1.0.*", - "raven/raven": "0.5.*", + "raven/raven": "~0.5", "ruflin/elastica": "0.90.*", "doctrine/couchdb": "dev-master", "aws/aws-sdk-php": "~2.4.8" From d37e9160402ce24830aecdc18b5827cd9b42343e Mon Sep 17 00:00:00 2001 From: Leevi Graham Date: Fri, 24 Jan 2014 00:31:57 +1100 Subject: [PATCH 23/30] Add limit to batched records --- src/Monolog/Handler/HipChatHandler.php | 92 ++++++++++++++++++-------- 1 file changed, 66 insertions(+), 26 deletions(-) diff --git a/src/Monolog/Handler/HipChatHandler.php b/src/Monolog/Handler/HipChatHandler.php index 5a6a46b0..1e75343c 100644 --- a/src/Monolog/Handler/HipChatHandler.php +++ b/src/Monolog/Handler/HipChatHandler.php @@ -32,6 +32,11 @@ class HipChatHandler extends SocketHandler */ const MAXIMUM_NAME_LENGTH = 15; + /** + * The maximum allowed length for the message. + */ + const MAXIMUM_MESSAGE_LENGTH = 9500; + /** * @var string */ @@ -63,7 +68,7 @@ class HipChatHandler extends SocketHandler */ public function __construct($token, $room, $name = 'Monolog', $notify = false, $level = Logger::CRITICAL, $bubble = true, $useSSL = true) { - if (!$this->validateName($name)) { + if (!$this->validateStringLength($name, static::MAXIMUM_NAME_LENGTH)) { throw new \InvalidArgumentException('The supplied name is too long. HipChat\'s v1 API supports names up to 15 UTF-8 characters.'); } @@ -168,14 +173,15 @@ class HipChatHandler extends SocketHandler return true; } - $batchRecord = $this->combineRecords($records); + $batchRecords = $this->combineRecords($records); - if (!$this->isHandling($batchRecord)) { - return false; + foreach($batchRecords as $batchRecord) { + + if ($this->isHandling($batchRecord)) { + $this->write($batchRecord); + } } - $this->write($batchRecord); - return false === $this->bubble; } @@ -189,6 +195,9 @@ class HipChatHandler extends SocketHandler */ private function combineRecords($records) { + $batchRecord = null; + $batchRecords = array(); + $batchedMessages = array(); $messages = array(); $formattedMessages = array(); $level = 0; @@ -198,10 +207,6 @@ class HipChatHandler extends SocketHandler foreach ($records as $record) { $record = $this->processRecord($record); - $record['formatted'] = $this->getFormatter()->format($record); - - $messages[] = $record['message']; - $formattedMessages[] = $record['formatted']; if ($record['level'] > $level) { $level = $record['level']; @@ -211,23 +216,56 @@ class HipChatHandler extends SocketHandler if (null === $datetime) { $datetime = $record['datetime']; } + + $messages[] = $record['message']; + $messgeStr = implode(PHP_EOL, $messages); + $formattedMessages[] = $this->getFormatter()->format($record); + $formattedMessageStr = implode('', $formattedMessages); + + $batchRecord = array( + 'message' => $messgeStr, + 'formatted' => $formattedMessageStr, + 'context' => array(), + 'extra' => array(), + ); + + if (!$this->validateStringLength($batchRecord['formatted'], static::MAXIMUM_MESSAGE_LENGTH)) { + + // Pop the last message and implode the remainging messages + $lastMessage = array_pop($messages); + $lastFormattedMessage = array_pop($formattedMessages); + $batchRecord['message'] = implode(PHP_EOL, $messages); + $batchRecord['formatted'] = implode('', $formattedMessages); + + $batchRecords[] = $batchRecord; + $messages = array($lastMessage); + $formattedMessages = array($lastFormattedMessage); + + $batchRecord = null; + } } - $batchRecord = array( - 'message' => implode(PHP_EOL, $messages), - 'formatted' => implode('', $formattedMessages), - 'level' => $level, - 'level_name' => $levelName, - 'datetime' => $datetime, - 'context' => array(), - 'extra' => array(), - ); + if (null !== $batchRecord) { + $batchRecords[] = $batchRecord; + } - return $batchRecord; + // Set the max level and datetime for all records + foreach ($batchRecords as &$batchRecord) { + $batchRecord = array_merge( + $batchRecord, + array( + 'level' => $level, + 'level_name' => $levelName, + 'datetime' => $datetime + ) + ); + } + + return $batchRecords; } /** - * Validates the supplied name for the "from" field. + * Validates the length of a string. * * If the `mb_strlen()` function is available, it will use that, as HipChat * allows UTF-8 characters. Otherwise, it will fall back to `strlen()`. @@ -236,15 +274,17 @@ class HipChatHandler extends SocketHandler * a valid name with less than 16 characters, but 16 or more bytes, on a * system where `mb_strlen()` is unavailable. * - * @param string $name Name to validate - * @return Boolean + * @param string $str + * @param int $length + * + * @return bool */ - private function validateName($name) + private function validateStringLength($str, $length) { if (function_exists('mb_strlen')) { - return (mb_strlen($name) <= static::MAXIMUM_NAME_LENGTH); + return (mb_strlen($str) <= $length); } - return (strlen($name) <= static::MAXIMUM_NAME_LENGTH); + return (strlen($str) <= $length); } } From 3a811ecfda637591a69fdfbd456f61b7beb46c3b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=A1bor=20T=C3=B3th?= Date: Wed, 29 Jan 2014 17:20:27 +0100 Subject: [PATCH 24/30] fix normalizing exception trace The trace does not include the file / line at which the exception is thrown --- src/Monolog/Formatter/NormalizerFormatter.php | 1 - tests/Monolog/Formatter/ScalarFormatterTest.php | 1 - 2 files changed, 2 deletions(-) diff --git a/src/Monolog/Formatter/NormalizerFormatter.php b/src/Monolog/Formatter/NormalizerFormatter.php index 765fed45..dfa3cb91 100644 --- a/src/Monolog/Formatter/NormalizerFormatter.php +++ b/src/Monolog/Formatter/NormalizerFormatter.php @@ -101,7 +101,6 @@ class NormalizerFormatter implements FormatterInterface ); $trace = $e->getTrace(); - array_shift($trace); foreach ($trace as $frame) { if (isset($frame['file'])) { $data['trace'][] = $frame['file'].':'.$frame['line']; diff --git a/tests/Monolog/Formatter/ScalarFormatterTest.php b/tests/Monolog/Formatter/ScalarFormatterTest.php index 6320c89e..b8cbb132 100644 --- a/tests/Monolog/Formatter/ScalarFormatterTest.php +++ b/tests/Monolog/Formatter/ScalarFormatterTest.php @@ -12,7 +12,6 @@ class ScalarFormatterTest extends \PHPUnit_Framework_TestCase { $data = array(); $trace = $e->getTrace(); - array_shift($trace); foreach ($trace as $frame) { if (isset($frame['file'])) { $data[] = $frame['file'].':'.$frame['line']; From 4814e79f3f8187824cd5332f0b67730514c041fc Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Thu, 6 Feb 2014 13:42:34 +0100 Subject: [PATCH 25/30] CS fixes and a BC nitpick --- src/Monolog/Handler/HipChatHandler.php | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/Monolog/Handler/HipChatHandler.php b/src/Monolog/Handler/HipChatHandler.php index 1e75343c..3f0b77b0 100644 --- a/src/Monolog/Handler/HipChatHandler.php +++ b/src/Monolog/Handler/HipChatHandler.php @@ -175,13 +175,18 @@ class HipChatHandler extends SocketHandler $batchRecords = $this->combineRecords($records); - foreach($batchRecords as $batchRecord) { - + $handled = false; + foreach ($batchRecords as $batchRecord) { if ($this->isHandling($batchRecord)) { $this->write($batchRecord); + $handled = true; } } + if (!$handled) { + return false; + } + return false === $this->bubble; } @@ -205,7 +210,6 @@ class HipChatHandler extends SocketHandler $datetime = null; foreach ($records as $record) { - $record = $this->processRecord($record); if ($record['level'] > $level) { @@ -230,7 +234,6 @@ class HipChatHandler extends SocketHandler ); if (!$this->validateStringLength($batchRecord['formatted'], static::MAXIMUM_MESSAGE_LENGTH)) { - // Pop the last message and implode the remainging messages $lastMessage = array_pop($messages); $lastFormattedMessage = array_pop($formattedMessages); From 6cabe95f23322735f446b00ca8582b6c875dcbfe Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Thu, 6 Feb 2014 21:34:59 +0100 Subject: [PATCH 26/30] Allow changing the HipChat message format, fixes #318 --- src/Monolog/Handler/HipChatHandler.php | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/Monolog/Handler/HipChatHandler.php b/src/Monolog/Handler/HipChatHandler.php index 3f0b77b0..3e400996 100644 --- a/src/Monolog/Handler/HipChatHandler.php +++ b/src/Monolog/Handler/HipChatHandler.php @@ -57,6 +57,11 @@ class HipChatHandler extends SocketHandler */ private $notify; + /** + * @var string + */ + private $format; + /** * @param string $token HipChat API Token * @param string $room The room that should be alerted of the message (Id or Name) @@ -65,8 +70,9 @@ class HipChatHandler extends SocketHandler * @param int $level The minimum logging level at which this handler will be triggered * @param Boolean $bubble Whether the messages that are handled can bubble up the stack or not * @param Boolean $useSSL Whether to connect via SSL. + * @param string $format The format of the messages (default to text, can be set to html if you have html in the messages) */ - public function __construct($token, $room, $name = 'Monolog', $notify = false, $level = Logger::CRITICAL, $bubble = true, $useSSL = true) + public function __construct($token, $room, $name = 'Monolog', $notify = false, $level = Logger::CRITICAL, $bubble = true, $useSSL = true, $format = 'text') { if (!$this->validateStringLength($name, static::MAXIMUM_NAME_LENGTH)) { throw new \InvalidArgumentException('The supplied name is too long. HipChat\'s v1 API supports names up to 15 UTF-8 characters.'); @@ -79,6 +85,7 @@ class HipChatHandler extends SocketHandler $this->name = $name; $this->notify = $notify; $this->room = $room; + $this->format = $format; } /** @@ -107,7 +114,7 @@ class HipChatHandler extends SocketHandler 'room_id' => $this->room, 'notify' => $this->notify, 'message' => $record['formatted'], - 'message_format' => 'text', + 'message_format' => $this->format, 'color' => $this->getAlertColor($record['level']), ); From 2aa09265fc1378072a0befec1e2891bc51369f1d Mon Sep 17 00:00:00 2001 From: Gunnar Lium Date: Fri, 14 Feb 2014 12:46:14 +0100 Subject: [PATCH 27/30] Strip inline line breaks from LineFormatter entries. --- src/Monolog/Formatter/LineFormatter.php | 20 +++++++++++-- tests/Monolog/Formatter/LineFormatterTest.php | 28 +++++++++++++++++++ 2 files changed, 45 insertions(+), 3 deletions(-) diff --git a/src/Monolog/Formatter/LineFormatter.php b/src/Monolog/Formatter/LineFormatter.php index af3d14b1..26f7aa12 100644 --- a/src/Monolog/Formatter/LineFormatter.php +++ b/src/Monolog/Formatter/LineFormatter.php @@ -26,14 +26,17 @@ class LineFormatter extends NormalizerFormatter const SIMPLE_FORMAT = "[%datetime%] %channel%.%level_name%: %message% %context% %extra%\n"; protected $format; + protected $allowInlineLineBreaks; /** - * @param string $format The format of the message - * @param string $dateFormat The format of the timestamp: one supported by DateTime::format + * @param string $format The format of the message + * @param string $dateFormat The format of the timestamp: one supported by DateTime::format + * @param bool $allowInlineLineBreaks Whether to allow inline line breaks in log entries */ - public function __construct($format = null, $dateFormat = null) + public function __construct($format = null, $dateFormat = null, $allowInlineLineBreaks = false) { $this->format = $format ?: static::SIMPLE_FORMAT; + $this->allowInlineLineBreaks = $allowInlineLineBreaks; parent::__construct($dateFormat); } @@ -57,6 +60,10 @@ class LineFormatter extends NormalizerFormatter } } + if (!$this->allowInlineLineBreaks) { + $output = $this->replaceInlineLineBreaks($output); + } + return $output; } @@ -98,4 +105,11 @@ class LineFormatter extends NormalizerFormatter return str_replace('\\/', '/', @json_encode($data)); } + + private function replaceInlineLineBreaks($output) + { + $suffix = substr($output, -1) === "\n" ? "\n" : ''; + + return trim(str_replace("\n", ' ', $output)) . $suffix; + } } diff --git a/tests/Monolog/Formatter/LineFormatterTest.php b/tests/Monolog/Formatter/LineFormatterTest.php index 7d7643a7..096e5644 100644 --- a/tests/Monolog/Formatter/LineFormatterTest.php +++ b/tests/Monolog/Formatter/LineFormatterTest.php @@ -150,6 +150,34 @@ class LineFormatterTest extends \PHPUnit_Framework_TestCase )); $this->assertEquals('['.date('Y-m-d').'] test.CRITICAL: bar [] []'."\n".'['.date('Y-m-d').'] log.WARNING: foo [] []'."\n", $message); } + + public function testFormatShouldStripInlineLineBreaks() + { + $formatter = new LineFormatter(null, 'Y-m-d'); + $message = $formatter->format( + array( + 'message' => "foo\nbar", + 'context' => array(), + 'extra' => array(), + ) + ); + + $this->assertRegExp('/foo bar/', $message); + } + + public function testFormatShouldNotStripInlineLineBreaksWhenFlagIsSet() + { + $formatter = new LineFormatter(null, 'Y-m-d', true); + $message = $formatter->format( + array( + 'message' => "foo\nbar", + 'context' => array(), + 'extra' => array(), + ) + ); + + $this->assertRegExp('/foo\nbar/', $message); + } } class TestFoo From 3638f9bfbbffda06abf542b8674738af2f1b29d6 Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Tue, 18 Feb 2014 14:59:31 +0100 Subject: [PATCH 28/30] Switch to psr-4 autoloading, closes #323 --- composer.json | 2 +- tests/bootstrap.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index 9b153194..bc14c439 100644 --- a/composer.json +++ b/composer.json @@ -34,7 +34,7 @@ "aws/aws-sdk-php": "Allow sending log messages to AWS services like DynamoDB" }, "autoload": { - "psr-0": {"Monolog": "src/"} + "psr-4": {"Monolog\\": "src/Monolog"} }, "extra": { "branch-alias": { diff --git a/tests/bootstrap.php b/tests/bootstrap.php index 05e49eda..b78740e2 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -10,6 +10,6 @@ */ $loader = require __DIR__ . "/../vendor/autoload.php"; -$loader->add('Monolog\\', __DIR__); +$loader->addPsr4('Monolog\\', __DIR__.'/Monolog'); date_default_timezone_set('UTC'); From 4c74b127eb5f1475157bb54c2b7cb3d529fe18f7 Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Tue, 18 Feb 2014 15:12:15 +0100 Subject: [PATCH 29/30] Tweak code to allow newlines in format, refs #322 --- src/Monolog/Formatter/LineFormatter.php | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/src/Monolog/Formatter/LineFormatter.php b/src/Monolog/Formatter/LineFormatter.php index 26f7aa12..9ef0a645 100644 --- a/src/Monolog/Formatter/LineFormatter.php +++ b/src/Monolog/Formatter/LineFormatter.php @@ -50,20 +50,16 @@ class LineFormatter extends NormalizerFormatter $output = $this->format; foreach ($vars['extra'] as $var => $val) { if (false !== strpos($output, '%extra.'.$var.'%')) { - $output = str_replace('%extra.'.$var.'%', $this->convertToString($val), $output); + $output = str_replace('%extra.'.$var.'%', $this->replaceNewlines($this->convertToString($val)), $output); unset($vars['extra'][$var]); } } foreach ($vars as $var => $val) { if (false !== strpos($output, '%'.$var.'%')) { - $output = str_replace('%'.$var.'%', $this->convertToString($val), $output); + $output = str_replace('%'.$var.'%', $this->replaceNewlines($this->convertToString($val)), $output); } } - if (!$this->allowInlineLineBreaks) { - $output = $this->replaceInlineLineBreaks($output); - } - return $output; } @@ -106,10 +102,12 @@ class LineFormatter extends NormalizerFormatter return str_replace('\\/', '/', @json_encode($data)); } - private function replaceInlineLineBreaks($output) + protected function replaceNewlines($str) { - $suffix = substr($output, -1) === "\n" ? "\n" : ''; + if ($this->allowInlineLineBreaks) { + return $str; + } - return trim(str_replace("\n", ' ', $output)) . $suffix; + return preg_replace('{[\r\n]+}', ' ', $str); } } From 17874ea306fc74dfe388db9f152bc27de7955f68 Mon Sep 17 00:00:00 2001 From: Tiago Brito Date: Wed, 19 Feb 2014 22:48:27 +0000 Subject: [PATCH 30/30] Change color levels Changed the Emergency color because the background was the same color as the foreground. And also changed the Alert and Critical colors to increase the contrast between these levels. --- src/Monolog/Formatter/HtmlFormatter.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Monolog/Formatter/HtmlFormatter.php b/src/Monolog/Formatter/HtmlFormatter.php index d853547b..f07c8715 100644 --- a/src/Monolog/Formatter/HtmlFormatter.php +++ b/src/Monolog/Formatter/HtmlFormatter.php @@ -30,9 +30,9 @@ class HtmlFormatter extends NormalizerFormatter Logger::NOTICE => '#3a87ad', Logger::WARNING => '#c09853', Logger::ERROR => '#f0ad4e', - Logger::CRITICAL => '#b94a48', - Logger::ALERT => '#d9534f', - Logger::EMERGENCY => '#ffffff', + Logger::CRITICAL => '#FF7708', + Logger::ALERT => '#C12A19', + Logger::EMERGENCY => '#000000', ); /**