From 95e8569b4d12e7a1bf0ad9e43367b6e53fd262b1 Mon Sep 17 00:00:00 2001 From: Adel Date: Wed, 11 Jul 2012 22:25:06 +0000 Subject: [PATCH 01/19] Remove unused @param --- src/Monolog/Handler/AmqpHandler.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Monolog/Handler/AmqpHandler.php b/src/Monolog/Handler/AmqpHandler.php index 09b13330..00703436 100644 --- a/src/Monolog/Handler/AmqpHandler.php +++ b/src/Monolog/Handler/AmqpHandler.php @@ -24,7 +24,6 @@ class AmqpHandler extends AbstractProcessingHandler /** * @param \AMQPExchange $exchange AMQP exchange, ready for use * @param string $exchangeName - * @param string $issuer issuer name * @param int $level * @param bool $bubble Whether the messages that are handled can bubble up the stack or not */ From 0a0c7a3a8174891d97576d00187e9843933918b1 Mon Sep 17 00:00:00 2001 From: Pascal Borreli Date: Fri, 13 Jul 2012 11:08:09 +0300 Subject: [PATCH 02/19] Removed duplicated array key --- tests/Monolog/Handler/AbstractProcessingHandlerTest.php | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/Monolog/Handler/AbstractProcessingHandlerTest.php b/tests/Monolog/Handler/AbstractProcessingHandlerTest.php index a8d31a83..d36132fa 100644 --- a/tests/Monolog/Handler/AbstractProcessingHandlerTest.php +++ b/tests/Monolog/Handler/AbstractProcessingHandlerTest.php @@ -64,7 +64,6 @@ class AbstractProcessingHandlerTest extends TestCase 'REQUEST_URI' => '', 'REQUEST_METHOD' => '', 'REMOTE_ADDR' => '', - 'REQUEST_URI' => '', 'SERVER_NAME' => '', ))); $handledRecord = null; From 0f89a6b26701407e8d318538d2a872805253c3c2 Mon Sep 17 00:00:00 2001 From: Alexandru Vilau Date: Sun, 22 Jul 2012 04:03:43 +0200 Subject: [PATCH 03/19] Improved default line formatter for syslog handler --- src/Monolog/Handler/SyslogHandler.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/Monolog/Handler/SyslogHandler.php b/src/Monolog/Handler/SyslogHandler.php index ed2fe441..6320fb13 100644 --- a/src/Monolog/Handler/SyslogHandler.php +++ b/src/Monolog/Handler/SyslogHandler.php @@ -107,4 +107,12 @@ class SyslogHandler extends AbstractProcessingHandler { syslog($this->logLevels[$record['level']], (string) $record['formatted']); } + + /** + * {@inheritdoc} + */ + protected function getDefaultFormatter() + { + return new LineFormatter('%channel%.%level_name%: %message% %context% %extra%\n'); + } } From 26adcea58256d07316a75c143d1afa4f0a1d9bb0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Haso=C5=88?= Date: Thu, 2 Aug 2012 13:10:43 +0200 Subject: [PATCH 04/19] Enabled float timeouts in SocketHandler --- src/Monolog/Handler/SocketHandler.php | 21 ++++++++++++--------- tests/Monolog/Handler/SocketHandlerTest.php | 8 ++++---- 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/src/Monolog/Handler/SocketHandler.php b/src/Monolog/Handler/SocketHandler.php index b44fad78..c9e857b2 100644 --- a/src/Monolog/Handler/SocketHandler.php +++ b/src/Monolog/Handler/SocketHandler.php @@ -89,7 +89,7 @@ class SocketHandler extends AbstractProcessingHandler /** * Set connection timeout. Only has effect before we connect. * - * @param integer $seconds + * @param float $seconds * * @see http://php.net/manual/en/function.fsockopen.php */ @@ -102,14 +102,14 @@ class SocketHandler extends AbstractProcessingHandler /** * Set write timeout. Only has effect before we connect. * - * @param type $seconds + * @param float $seconds * * @see http://php.net/manual/en/function.stream-set-timeout.php */ public function setTimeout($seconds) { $this->validateTimeout($seconds); - $this->timeout = (int) $seconds; + $this->timeout = (float) $seconds; } /** @@ -183,10 +183,15 @@ class SocketHandler extends AbstractProcessingHandler /** * Wrapper to allow mocking + * + * @see http://php.net/manual/en/function.stream-set-timeout.php */ protected function streamSetTimeout() { - return stream_set_timeout($this->resource, $this->timeout); + $seconds = floor($this->timeout); + $microseconds = round(($this->timeout - $seconds)*1e6); + + return stream_set_timeout($this->resource, $seconds, $microseconds); } /** @@ -207,11 +212,9 @@ class SocketHandler extends AbstractProcessingHandler private function validateTimeout($value) { - $ok = filter_var($value, FILTER_VALIDATE_INT, array('options' => array( - 'min_range' => 0, - ))); - if ($ok === false) { - throw new \InvalidArgumentException("Timeout must be 0 or a positive integer (got $value)"); + $ok = filter_var($value, FILTER_VALIDATE_FLOAT); + if ($ok === false || $value < 0) { + throw new \InvalidArgumentException("Timeout must be 0 or a positive float (got $value)"); } } diff --git a/tests/Monolog/Handler/SocketHandlerTest.php b/tests/Monolog/Handler/SocketHandlerTest.php index e3013050..c642bea8 100644 --- a/tests/Monolog/Handler/SocketHandlerTest.php +++ b/tests/Monolog/Handler/SocketHandlerTest.php @@ -50,8 +50,8 @@ class SocketHandlerTest extends TestCase public function testSetConnectionTimeout() { $this->createHandler('localhost:1234'); - $this->handler->setConnectionTimeout(10); - $this->assertEquals(10, $this->handler->getConnectionTimeout()); + $this->handler->setConnectionTimeout(10.1); + $this->assertEquals(10.1, $this->handler->getConnectionTimeout()); } /** @@ -66,8 +66,8 @@ class SocketHandlerTest extends TestCase public function testSetTimeout() { $this->createHandler('localhost:1234'); - $this->handler->setTimeout(10); - $this->assertEquals(10, $this->handler->getTimeout()); + $this->handler->setTimeout(10.25); + $this->assertEquals(10.25, $this->handler->getTimeout()); } public function testSetConnectionString() From 535cea507f1320ab82af0c493531127178e17726 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Haso=C5=88?= Date: Thu, 2 Aug 2012 13:21:20 +0200 Subject: [PATCH 05/19] Avoid memory leak in SocketHandler (substr function in the first iteration) --- src/Monolog/Handler/SocketHandler.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/Monolog/Handler/SocketHandler.php b/src/Monolog/Handler/SocketHandler.php index c9e857b2..1aaa22a5 100644 --- a/src/Monolog/Handler/SocketHandler.php +++ b/src/Monolog/Handler/SocketHandler.php @@ -257,7 +257,11 @@ class SocketHandler extends AbstractProcessingHandler $length = strlen($data); $sent = 0; while ($this->isConnected() && $sent < $length) { - $chunk = $this->fwrite(substr($data, $sent)); + if (0 == $sent) { + $chunk = $this->fwrite($data); + } else { + $chunk = $this->fwrite(substr($data, $sent)); + } if ($chunk === false) { throw new \RuntimeException("Could not write to socket"); } From 103ab255a8db02386cdd4d59fc02c554afba53c5 Mon Sep 17 00:00:00 2001 From: Luis Cordova Date: Fri, 3 Aug 2012 03:30:04 -0500 Subject: [PATCH 06/19] rephrased for clarity and simplicity --- doc/usage.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/doc/usage.md b/doc/usage.md index a3cfc7ff..0be6f0e6 100644 --- a/doc/usage.md +++ b/doc/usage.md @@ -94,12 +94,12 @@ Leveraging channels Channels are a great way to identify to which part of the application a record is related. This is useful in big applications (and is leveraged by -MonologBundle in Symfony2). You can then easily grep through log files for -example to filter this or that type of log record. +MonologBundle in Symfony2). -Using different loggers with the same handlers allow to identify the logger -that issued the record (through the channel name) by keeping the same handlers -(for instance to use a single log file). +Picture two loggers sharing a handler that writes to a single log file. +Channels would then allow an identity of the logger that issues the record +(distinguishable through the channel's name). You can then easily grep through +the log files filtering this or that type of log record. ```php Date: Fri, 10 Aug 2012 02:15:26 +0300 Subject: [PATCH 07/19] Minor wording adjustment in the docs --- doc/usage.md | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/doc/usage.md b/doc/usage.md index 0be6f0e6..98db29ae 100644 --- a/doc/usage.md +++ b/doc/usage.md @@ -97,9 +97,8 @@ is related. This is useful in big applications (and is leveraged by MonologBundle in Symfony2). Picture two loggers sharing a handler that writes to a single log file. -Channels would then allow an identity of the logger that issues the record -(distinguishable through the channel's name). You can then easily grep through -the log files filtering this or that type of log record. +Channels would allow you to identify the logger that issued every record. +You can easily grep through the log files filtering this or that channel. ```php Date: Sat, 18 Aug 2012 18:14:57 +0200 Subject: [PATCH 08/19] Improve error reporting on failed streams, refs #85 --- src/Monolog/Handler/StreamHandler.php | 9 +++++++-- tests/Monolog/Handler/StreamHandlerTest.php | 11 +++++++++++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/Monolog/Handler/StreamHandler.php b/src/Monolog/Handler/StreamHandler.php index a4370300..96ce7fc0 100644 --- a/src/Monolog/Handler/StreamHandler.php +++ b/src/Monolog/Handler/StreamHandler.php @@ -60,10 +60,15 @@ class StreamHandler extends AbstractProcessingHandler if (!$this->url) { throw new \LogicException('Missing stream url, the stream can not be opened. This may be caused by a premature call to close().'); } - $this->stream = @fopen($this->url, 'a'); + $errorMessage = null; + set_error_handler(function ($code, $msg) use (&$errorMessage) { + $errorMessage = preg_replace('{^fopen\(.*?\): }', '', $msg); + }); + $this->stream = fopen($this->url, 'a'); + restore_error_handler(); if (!is_resource($this->stream)) { $this->stream = null; - throw new \UnexpectedValueException(sprintf('The stream or file "%s" could not be opened; it may be invalid or not writable.', $this->url)); + throw new \UnexpectedValueException(sprintf('The stream or file "%s" could not be opened: '.$errorMessage, $this->url)); } } fwrite($this->stream, (string) $record['formatted']); diff --git a/tests/Monolog/Handler/StreamHandlerTest.php b/tests/Monolog/Handler/StreamHandlerTest.php index 6f7cbec1..63d4fef6 100644 --- a/tests/Monolog/Handler/StreamHandlerTest.php +++ b/tests/Monolog/Handler/StreamHandlerTest.php @@ -74,4 +74,15 @@ class StreamHandlerTest extends TestCase $handler = new StreamHandler('bogus://url'); $handler->handle($this->getRecord()); } + + /** + * @expectedException UnexpectedValueException + * @covers Monolog\Handler\StreamHandler::__construct + * @covers Monolog\Handler\StreamHandler::write + */ + public function testWriteNonExistingResource() + { + $handler = new StreamHandler('/foo/bar/baz/'.rand(0, 10000)); + $handler->handle($this->getRecord()); + } } From 7c2ca1c61c23475921cb96eb52d1f688562ff74e Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Sat, 18 Aug 2012 18:51:10 +0200 Subject: [PATCH 09/19] CubeHandler cleanup --- .gitignore | 3 +- README.mdown | 1 + src/Monolog/Handler/CubeHandler.php | 117 ++++++++++++---------------- 3 files changed, 50 insertions(+), 71 deletions(-) diff --git a/.gitignore b/.gitignore index 6e964676..0a3fb552 100644 --- a/.gitignore +++ b/.gitignore @@ -2,5 +2,4 @@ vendor composer.phar phpunit.xml composer.lock - -.DS_Store \ No newline at end of file +.DS_Store diff --git a/README.mdown b/README.mdown index 0e40fb77..c051eb19 100644 --- a/README.mdown +++ b/README.mdown @@ -113,6 +113,7 @@ Handlers for UNIX and TCP sockets. See an [example](https://github.com/Seldaek/monolog/blob/master/doc/sockets.md). - _AmqpHandler_: Logs records to an [amqp](http://www.amqp.org/) compatible server. Requires the [php-amqp](http://pecl.php.net/package/amqp) extension (1.0+). +- _CubeHandler_: Logs records to a [Cube](http://square.github.com/cube/) server. Wrappers / Special Handlers --------------------------- diff --git a/src/Monolog/Handler/CubeHandler.php b/src/Monolog/Handler/CubeHandler.php index 5819a407..c21e0e3e 100644 --- a/src/Monolog/Handler/CubeHandler.php +++ b/src/Monolog/Handler/CubeHandler.php @@ -1,5 +1,5 @@ */ class CubeHandler extends AbstractProcessingHandler { private $udpConnection = null; private $httpConnection = null; - private $scheme = null; private $host = null; private $port = null; - private $acceptedScheme = array('http', 'udp'); - - + private $acceptedSchemes = array('http', 'udp'); + /** * Create a Cube handler * @@ -40,36 +38,23 @@ class CubeHandler extends AbstractProcessingHandler public function __construct($url, $level = Logger::DEBUG, $bubble = true) { $urlInfos = parse_url($url); - - if (!$urlInfos || !isset($urlInfos['scheme']) - || !isset($urlInfos['host']) || !isset($urlInfos['port'])) { + + if (!isset($urlInfos['scheme']) || !isset($urlInfos['host']) || !isset($urlInfos['port'])) { throw new \UnexpectedValueException('URL "'.$url.'" is not valid'); } - - if (!in_array($urlInfos['scheme'], $this->acceptedScheme)) { + + if (!in_array($urlInfos['scheme'], $this->acceptedSchemes)) { throw new \UnexpectedValueException( - 'Invalid ' . $urlInfos['scheme'] . ' protocol.' - . 'Valid options are ' . implode(', ', $this->acceptedScheme)); - } else { - $this->scheme = $urlInfos['scheme']; - $this->host = $urlInfos['host']; - $this->port = $urlInfos['port']; + 'Invalid protocol (' . $urlInfos['scheme'] . ').' + . ' Valid options are ' . implode(', ', $this->acceptedSchemes)); } - + + $this->scheme = $urlInfos['scheme']; + $this->host = $urlInfos['host']; + $this->port = $urlInfos['port']; + parent::__construct($level, $bubble); } - - - /** - * Check if a connection resource is available - * - * @return boolean - */ - private function isConnected($scheme) - { - return $this->{$scheme . 'Connection'} !== null; - } - /** * Establish a connection to an UDP socket @@ -79,88 +64,82 @@ class CubeHandler extends AbstractProcessingHandler protected function connectUdp() { if (!extension_loaded('sockets')) { - throw new \LogicException('The sockets extension is not loaded'); + throw new \LogicException('The sockets extension is needed to use udp URLs with the CubeHandler'); } - + $this->udpConnection = socket_create(AF_INET, SOCK_DGRAM, 0); if (!$this->udpConnection) { throw new \LogicException('Unable to create a socket'); } if (!socket_connect($this->udpConnection, $this->host, $this->port)) { - throw new \LogicException('Unable to connect to the socket at ' - . $this->host . ':' . $this->port); + throw new \LogicException('Unable to connect to the socket at ' . $this->host . ':' . $this->port); } } - /** * Establish a connection to a http server */ protected function connectHttp() { - $this->httpConnection = - curl_init('http://'.$this->host.':'.$this->port.'/1.0/event/put'); - + if (!extension_loaded('curl')) { + throw new \LogicException('The curl extension is needed to use http URLs with the CubeHandler'); + } + + $this->httpConnection = curl_init('http://'.$this->host.':'.$this->port.'/1.0/event/put'); + if (!$this->httpConnection) { - throw new \LogicException('Unable to connect to ' - . $this->host . ':' . $this->port); + throw new \LogicException('Unable to connect to ' . $this->host . ':' . $this->port); } curl_setopt($this->httpConnection, CURLOPT_CUSTOMREQUEST, "POST"); curl_setopt($this->httpConnection, CURLOPT_RETURNTRANSFER, true); - } - - + /** * {@inheritdoc} */ protected function write(array $record) { $date = $record['datetime']; - - $datas = array('time' => $date->format('Y-m-d H:i:s')); + + $data = array('time' => $date->format('Y-m-d H:i:s')); unset($record['datetime']); if (isset($record['context']['type'])) { - $datas['type'] = $record['context']['type']; + $data['type'] = $record['context']['type']; unset($record['context']['type']); } else { - $datas['type'] = $record['channel']; + $data['type'] = $record['channel']; } - - $datas['data'] = $record['context']; - $datas['data']['level'] = $record['level']; - - call_user_func( - array($this, 'send'.ucwords($this->scheme)), json_encode($datas)); + + $data['data'] = $record['context']; + $data['data']['level'] = $record['level']; + + $this->{'write'.$this->scheme}(json_encode($data)); } - - private function sendUdp($datas) + private function writeUdp($data) { - if (!$this->isConnected($this->scheme)) { - call_user_func( - array($this, 'connect' . ucwords($this->scheme))); + if (!$this->udpConnection) { + $this->connectUdp(); } - socket_send($this->udpConnection, $datas, strlen($datas), 0); + socket_send($this->udpConnection, $data, strlen($data), 0); } - - private function sendHttp($datas) + private function writeHttp($data) { - if (!$this->isConnected($this->scheme)) { - call_user_func( - array($this, 'connect' . ucwords($this->scheme))); + if (!$this->httpConnection) { + $this->connectHttp(); } - curl_setopt($this->httpConnection, CURLOPT_POSTFIELDS, '['.$datas.']'); + curl_setopt($this->httpConnection, CURLOPT_POSTFIELDS, '['.$data.']'); curl_setopt($this->httpConnection, CURLOPT_HTTPHEADER, array( 'Content-Type: application/json', - 'Content-Length: ' . strlen('['.$datas.']')) + 'Content-Length: ' . strlen('['.$data.']')) ); + return curl_exec($this->httpConnection); } } \ No newline at end of file From 7940ae31ce4687d875d2bb5aa277bb3802203fe1 Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Sat, 18 Aug 2012 19:27:13 +0200 Subject: [PATCH 10/19] Update changelog --- CHANGELOG.mdown | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/CHANGELOG.mdown b/CHANGELOG.mdown index ddaa16ee..849d3381 100644 --- a/CHANGELOG.mdown +++ b/CHANGELOG.mdown @@ -1,3 +1,18 @@ +* 1.2.0 (2012-08-18) + + Changes: + + * Added AmqpHandler (for use with AMQP servers) + * Added CubeHandler + * Added NativeMailerHandler::addHeader() to send custom headers in mails + * Added the possibility to specify more than one recipient in NativeMailerHandler + * Added the possibility to specify float timeouts in SocketHandler + * Added NOTICE and EMERGENCY levels to conform with RFC 5424 + * Fixed the log records to use the php default timezone instead of UTC + * Fixed BufferHandler not being flushed properly on PHP fatal errors + * Fixed normalization of exotic resource types + * Fixed the default format of the SyslogHandler to avoid duplicating datetimes in syslog + * 1.1.0 (2012-04-23) Changes: From f8fce6fd541d62992952b1146bca05e45ebb1efb Mon Sep 17 00:00:00 2001 From: Geoffrey Tran Date: Sat, 25 Aug 2012 12:01:32 -0500 Subject: [PATCH 11/19] Update src/Monolog/Handler/SyslogHandler.php Missing use statement for LineFormatter, which causes a fatal exception. --- src/Monolog/Handler/SyslogHandler.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Monolog/Handler/SyslogHandler.php b/src/Monolog/Handler/SyslogHandler.php index 6320fb13..f569f44c 100644 --- a/src/Monolog/Handler/SyslogHandler.php +++ b/src/Monolog/Handler/SyslogHandler.php @@ -12,6 +12,8 @@ namespace Monolog\Handler; use Monolog\Logger; +use Monolog\Formatter\LineFormatter; + /** * Logs to syslog service. From 76fb21b31b6e9ffedfd9ffbbd2ffee3b2a4af2e9 Mon Sep 17 00:00:00 2001 From: David Zuelke Date: Wed, 29 Aug 2012 10:54:14 +0200 Subject: [PATCH 12/19] Allow passing of openlog() options in SyslogHandler ctor --- src/Monolog/Handler/SyslogHandler.php | 4 ++-- tests/Monolog/Handler/SyslogHandlerTest.php | 4 ++++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/Monolog/Handler/SyslogHandler.php b/src/Monolog/Handler/SyslogHandler.php index f569f44c..628621f7 100644 --- a/src/Monolog/Handler/SyslogHandler.php +++ b/src/Monolog/Handler/SyslogHandler.php @@ -67,7 +67,7 @@ class SyslogHandler extends AbstractProcessingHandler * @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 */ - public function __construct($ident, $facility = LOG_USER, $level = Logger::DEBUG, $bubble = true) + public function __construct($ident, $facility = LOG_USER, $level = Logger::DEBUG, $bubble = true, $logopts = LOG_PID) { parent::__construct($level, $bubble); @@ -89,7 +89,7 @@ class SyslogHandler extends AbstractProcessingHandler throw new \UnexpectedValueException('Unknown facility value "'.$facility.'" given'); } - if (!openlog($ident, LOG_PID, $facility)) { + if (!openlog($ident, $logopts, $facility)) { throw new \LogicException('Can\'t open syslog for ident "'.$ident.'" and facility "'.$facility.'"'); } } diff --git a/tests/Monolog/Handler/SyslogHandlerTest.php b/tests/Monolog/Handler/SyslogHandlerTest.php index 88e09b77..98219ac1 100644 --- a/tests/Monolog/Handler/SyslogHandlerTest.php +++ b/tests/Monolog/Handler/SyslogHandlerTest.php @@ -10,6 +10,7 @@ */ namespace Monolog\Handler; +use Monolog\Logger; class SyslogHandlerTest extends \PHPUnit_Framework_TestCase { @@ -26,6 +27,9 @@ class SyslogHandlerTest extends \PHPUnit_Framework_TestCase $handler = new SyslogHandler('test', 'user'); $this->assertInstanceOf('Monolog\Handler\SyslogHandler', $handler); + + $handler = new SyslogHandler('test', LOG_USER, Logger::DEBUG, true, LOG_PERROR); + $this->assertInstanceOf('Monolog\Handler\SyslogHandler', $handler); } /** From 1feffd31fd24e785f0a6f93975179e189f498af8 Mon Sep 17 00:00:00 2001 From: David Zuelke Date: Wed, 29 Aug 2012 11:23:13 +0200 Subject: [PATCH 13/19] add arg docs --- src/Monolog/Handler/SyslogHandler.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Monolog/Handler/SyslogHandler.php b/src/Monolog/Handler/SyslogHandler.php index 628621f7..023b8811 100644 --- a/src/Monolog/Handler/SyslogHandler.php +++ b/src/Monolog/Handler/SyslogHandler.php @@ -66,6 +66,7 @@ class SyslogHandler extends AbstractProcessingHandler * @param mixed $facility * @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 int $logopts Option flags for the openlog() call, defaults to LOG_PID */ public function __construct($ident, $facility = LOG_USER, $level = Logger::DEBUG, $bubble = true, $logopts = LOG_PID) { From d16496318c3e08e3bccfc3866e104e49cf25488a Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Wed, 29 Aug 2012 13:53:20 +0200 Subject: [PATCH 14/19] Update changelog & branch alias --- CHANGELOG.mdown | 7 +++++++ composer.json | 7 ++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.mdown b/CHANGELOG.mdown index 849d3381..b9f93c7d 100644 --- a/CHANGELOG.mdown +++ b/CHANGELOG.mdown @@ -1,3 +1,10 @@ +* 1.2.1 (2012-08-29) + + Changes: + + * Added new $logopts arg to SyslogHandler to provide custom openlog options + * Fixed fatal error in SyslogHandler + * 1.2.0 (2012-08-18) Changes: diff --git a/composer.json b/composer.json index 03829a81..9db9073a 100644 --- a/composer.json +++ b/composer.json @@ -1,7 +1,7 @@ { "name": "monolog/monolog", "description": "Logging for PHP 5.3", - "keywords": ["log","logging"], + "keywords": ["log", "logging"], "homepage": "http://github.com/Seldaek/monolog", "type": "library", "license": "MIT", @@ -25,5 +25,10 @@ }, "autoload": { "psr-0": {"Monolog": "src/"} + }, + "extra": { + "branch-alias": { + "dev-master": "1.3.x-dev" + } } } From a929570bb7688b39fefe4106f0ecf0ac35f37647 Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Wed, 5 Sep 2012 21:32:46 +0200 Subject: [PATCH 15/19] Fix json encoding, fixes #110 --- src/Monolog/Formatter/LineFormatter.php | 2 +- tests/Monolog/Formatter/LineFormatterTest.php | 7 ++----- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/src/Monolog/Formatter/LineFormatter.php b/src/Monolog/Formatter/LineFormatter.php index 1054dbba..dd116967 100644 --- a/src/Monolog/Formatter/LineFormatter.php +++ b/src/Monolog/Formatter/LineFormatter.php @@ -85,6 +85,6 @@ class LineFormatter extends NormalizerFormatter return json_encode($this->normalize($data), JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE); } - return stripslashes(json_encode($this->normalize($data))); + return str_replace('\\/', '/', json_encode($this->normalize($data))); } } diff --git a/tests/Monolog/Formatter/LineFormatterTest.php b/tests/Monolog/Formatter/LineFormatterTest.php index 9e80917b..e3516f73 100644 --- a/tests/Monolog/Formatter/LineFormatterTest.php +++ b/tests/Monolog/Formatter/LineFormatterTest.php @@ -86,11 +86,8 @@ class LineFormatterTest extends \PHPUnit_Framework_TestCase 'extra' => array('foo' => new TestFoo, 'bar' => new TestBar, 'baz' => array(), 'res' => fopen('php://memory', 'rb')), 'message' => 'foobar', )); - if (version_compare(PHP_VERSION, '5.4.0', '>=')) { - $this->assertEquals('['.date('Y-m-d').'] meh.ERROR: foobar [] {"foo":"[object] (Monolog\\\\Formatter\\\\TestFoo: {\\"foo\\":\\"foo\\"})","bar":"[object] (Monolog\\\\Formatter\\\\TestBar: {})","baz":[],"res":"[resource]"}'."\n", $message); - } else { - $this->assertEquals('['.date('Y-m-d').'] meh.ERROR: foobar [] {"foo":"[object] (Monolog\\Formatter\\TestFoo: {"foo":"foo"})","bar":"[object] (Monolog\\Formatter\\TestBar: {})","baz":[],"res":"[resource]"}'."\n", $message); - } + + $this->assertEquals('['.date('Y-m-d').'] meh.ERROR: foobar [] {"foo":"[object] (Monolog\\\\Formatter\\\\TestFoo: {\\"foo\\":\\"foo\\"})","bar":"[object] (Monolog\\\\Formatter\\\\TestBar: {})","baz":[],"res":"[resource]"}'."\n", $message); } public function testBatchFormat() From 48729c02c8ab79be5df325926548443dd42a4882 Mon Sep 17 00:00:00 2001 From: Jimmy Berry Date: Fri, 7 Sep 2012 23:06:35 -0700 Subject: [PATCH 16/19] Correct handler comment. --- 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 0ff2aa83..2c1f13f6 100644 --- a/src/Monolog/Logger.php +++ b/src/Monolog/Logger.php @@ -194,7 +194,7 @@ class Logger 'datetime' => \DateTime::createFromFormat('U.u', sprintf('%.6F', microtime(true)))->setTimeZone(self::$timezone), 'extra' => array(), ); - // check if any message will handle this message + // check if any handler will handle this message $handlerKey = null; foreach ($this->handlers as $key => $handler) { if ($handler->isHandling($record)) { From 2fec0273b3dd26e747cf3dc439265b05c29781ab Mon Sep 17 00:00:00 2001 From: Tomasz Ducin Date: Tue, 11 Sep 2012 00:01:20 +0200 Subject: [PATCH 17/19] new section: customizing logger output format --- doc/usage.md | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/doc/usage.md b/doc/usage.md index 98db29ae..8c5e8e2d 100644 --- a/doc/usage.md +++ b/doc/usage.md @@ -121,3 +121,38 @@ $securityLogger = new Logger('security'); $securityLogger->pushHandler($stream); $securityLogger->pushHandler($firephp); ``` + +Customizing log format +---------------------- + +In Monolog it's easy to customize the format of the logs written into files, +sockets, mails, databases and other handlers. Most of the handlers use the + +```php +$record['formatted'] +``` + +value to be automatically put into the log device. This value depends on the +formatter settings. You can choose between predefined formatter classes or +write your own (e.g. a multiline text file for human-readable output). + +To configure a predefined formatter class, just set it as the handler's field: + +```php +// the default date format is "Y-m-d H:i:s" +$dateFormat = "Y n j, g:i a"; +// the default output format is "[%datetime%] %channel%.%level_name%: %message% %context% %extra%\n" +$output = "%datetime% > %level_name% > %message% %context% %extra%\n" +// finally, create a formatter +$formatter = new LineFormatter($output, $dateFormat); + +// Create a handler +$stream = new StreamHandler(__DIR__.'/my_app.log', Logger::DEBUG); +$stream->setFormatter($formatter); +// bind it to a logger object +$securityLogger = new Logger('security'); +$securityLogger->pushHandler($stream); +``` + +You may also reuse the same formatter between multiple handlers and share those +handlers between multiple loggers. From 22803f1f2d135e67694699c03092a950412c2381 Mon Sep 17 00:00:00 2001 From: Pascal Borreli Date: Mon, 17 Sep 2012 21:54:25 +0000 Subject: [PATCH 18/19] Fixed PHPDoc --- src/Monolog/Handler/HandlerInterface.php | 2 ++ src/Monolog/Handler/NativeMailerHandler.php | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Monolog/Handler/HandlerInterface.php b/src/Monolog/Handler/HandlerInterface.php index d24dc775..9988d9d5 100644 --- a/src/Monolog/Handler/HandlerInterface.php +++ b/src/Monolog/Handler/HandlerInterface.php @@ -25,6 +25,8 @@ interface HandlerInterface * * This is mostly done for performance reasons, to avoid calling processors for nothing. * + * @param array $record + * * @return Boolean */ public function isHandling(array $record); diff --git a/src/Monolog/Handler/NativeMailerHandler.php b/src/Monolog/Handler/NativeMailerHandler.php index c954de5d..3a0e9356 100644 --- a/src/Monolog/Handler/NativeMailerHandler.php +++ b/src/Monolog/Handler/NativeMailerHandler.php @@ -42,7 +42,7 @@ class NativeMailerHandler extends MailHandler } /** - * @param string|array $header Custom added headers + * @param string|array $headers Custom added headers */ public function addHeader($headers) { From 09168eaca845ce304c70a5557f3037244aaae5c1 Mon Sep 17 00:00:00 2001 From: Rob Loach Date: Fri, 12 Oct 2012 12:54:44 -0400 Subject: [PATCH 19/19] Fix whitespace --- .travis.yml | 2 +- src/Monolog/Handler/CubeHandler.php | 2 +- src/Monolog/Handler/SocketHandler.php | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index eb350496..ea5262a9 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,6 @@ language: php -php: +php: - 5.3 - 5.4 diff --git a/src/Monolog/Handler/CubeHandler.php b/src/Monolog/Handler/CubeHandler.php index c21e0e3e..b8150071 100644 --- a/src/Monolog/Handler/CubeHandler.php +++ b/src/Monolog/Handler/CubeHandler.php @@ -142,4 +142,4 @@ class CubeHandler extends AbstractProcessingHandler return curl_exec($this->httpConnection); } -} \ No newline at end of file +} diff --git a/src/Monolog/Handler/SocketHandler.php b/src/Monolog/Handler/SocketHandler.php index 1aaa22a5..92de217c 100644 --- a/src/Monolog/Handler/SocketHandler.php +++ b/src/Monolog/Handler/SocketHandler.php @@ -190,7 +190,7 @@ class SocketHandler extends AbstractProcessingHandler { $seconds = floor($this->timeout); $microseconds = round(($this->timeout - $seconds)*1e6); - + return stream_set_timeout($this->resource, $seconds, $microseconds); }