From b4a33da36384371d51bbc00366cfe796cfdf9c8e Mon Sep 17 00:00:00 2001 From: pomaxa Date: Tue, 12 Jun 2012 16:48:32 +0300 Subject: [PATCH 01/14] amqp handler.. need to test --- src/Monolog/Handler/AmqpHandler.php | 50 +++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 src/Monolog/Handler/AmqpHandler.php diff --git a/src/Monolog/Handler/AmqpHandler.php b/src/Monolog/Handler/AmqpHandler.php new file mode 100644 index 00000000..e7f0c2eb --- /dev/null +++ b/src/Monolog/Handler/AmqpHandler.php @@ -0,0 +1,50 @@ + + */ +class AmqpHandler extends AbstractProcessingHandler +{ + protected $exchange; + protected $space; + function __construct(\AMQPConnection $amqp, $exchange = 'log', $space = '', $level = Logger::DEBUG, $bubble = true) + { + $channel = new \AMQPChannel($amqp); + $this->exchange = new \AMQPExchange($channel); + $this->exchange->setName($exchange); + parent::__construct($level, $bubble); + } + + /** + * Writes the record down to the log of the implementing handler + * + * @param array $record + * @return void + */ + protected function write(array $record) + { + + $data = json_encode($record["formatted"]); + + $routingKey = substr(strtolower($record['level_name']),0,4 ).'.'.$this->space; + + $this->exchange->publish($data, $routingKey, 0, + array('delivery_mode' => 2, 'Content-type' => 'application/json')); + } + + /** + * {@inheritDoc} + */ + protected function getDefaultFormatter() + { + return new NormalizerFormatter(); + } +} \ No newline at end of file From 4c46dce153091352ac141e33f41d73caef6e2b7b Mon Sep 17 00:00:00 2001 From: pomaxa Date: Wed, 13 Jun 2012 11:17:30 +0300 Subject: [PATCH 02/14] Fixed issues --- src/Monolog/Handler/AmqpHandler.php | 31 +++++++++++++++++++---------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/src/Monolog/Handler/AmqpHandler.php b/src/Monolog/Handler/AmqpHandler.php index e7f0c2eb..f1291cee 100644 --- a/src/Monolog/Handler/AmqpHandler.php +++ b/src/Monolog/Handler/AmqpHandler.php @@ -1,22 +1,34 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + namespace Monolog\Handler; use Monolog\Logger; -use Monolog\Formatter\NormalizerFormatter; use Monolog\Formatter\JsonFormatter; -/** - * handle sending logs to the rabbitmq, using Amqp protocol; - * - * @author pomaxa none - */ class AmqpHandler extends AbstractProcessingHandler { protected $exchange; protected $space; + + /** + * @param \AMQPConnection $amqp Amqp connection, ready for use + * @param string $exchange exchange name + * @param string $space string to be able better manage routing keys + * @param int $level + * @param bool $bubble + */ function __construct(\AMQPConnection $amqp, $exchange = 'log', $space = '', $level = Logger::DEBUG, $bubble = true) { + $this->space = $space; $channel = new \AMQPChannel($amqp); $this->exchange = new \AMQPExchange($channel); $this->exchange->setName($exchange); @@ -31,11 +43,8 @@ class AmqpHandler extends AbstractProcessingHandler */ protected function write(array $record) { - - $data = json_encode($record["formatted"]); - + $data = $record["formatted"]; $routingKey = substr(strtolower($record['level_name']),0,4 ).'.'.$this->space; - $this->exchange->publish($data, $routingKey, 0, array('delivery_mode' => 2, 'Content-type' => 'application/json')); } @@ -45,6 +54,6 @@ class AmqpHandler extends AbstractProcessingHandler */ protected function getDefaultFormatter() { - return new NormalizerFormatter(); + return new JsonFormatter(); } } \ No newline at end of file From be762cb0c5b77cd3d722ca36e434b58f2c876201 Mon Sep 17 00:00:00 2001 From: pomaxa Date: Wed, 13 Jun 2012 11:21:22 +0300 Subject: [PATCH 03/14] style --- src/Monolog/Handler/AmqpHandler.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Monolog/Handler/AmqpHandler.php b/src/Monolog/Handler/AmqpHandler.php index f1291cee..e802ed03 100644 --- a/src/Monolog/Handler/AmqpHandler.php +++ b/src/Monolog/Handler/AmqpHandler.php @@ -24,7 +24,7 @@ class AmqpHandler extends AbstractProcessingHandler * @param string $exchange exchange name * @param string $space string to be able better manage routing keys * @param int $level - * @param bool $bubble + * @param bool $bubble Whether the messages that are handled can bubble up the stack or not */ function __construct(\AMQPConnection $amqp, $exchange = 'log', $space = '', $level = Logger::DEBUG, $bubble = true) { @@ -56,4 +56,4 @@ class AmqpHandler extends AbstractProcessingHandler { return new JsonFormatter(); } -} \ No newline at end of file +} From a56543682d53801091c505ef2a49cb7f6d4718a8 Mon Sep 17 00:00:00 2001 From: pomaxa Date: Wed, 13 Jun 2012 12:07:17 +0300 Subject: [PATCH 04/14] AMQP --- src/Monolog/Handler/AmqpHandler.php | 10 ++-- tests/Monolog/Handler/AmqpHandlerTest.php | 50 +++++++++++++++++++ tests/Monolog/Handler/AmqpMocks.php | 61 +++++++++++++++++++++++ 3 files changed, 117 insertions(+), 4 deletions(-) create mode 100644 tests/Monolog/Handler/AmqpHandlerTest.php create mode 100644 tests/Monolog/Handler/AmqpMocks.php diff --git a/src/Monolog/Handler/AmqpHandler.php b/src/Monolog/Handler/AmqpHandler.php index e802ed03..a3f95244 100644 --- a/src/Monolog/Handler/AmqpHandler.php +++ b/src/Monolog/Handler/AmqpHandler.php @@ -16,22 +16,24 @@ use Monolog\Formatter\JsonFormatter; class AmqpHandler extends AbstractProcessingHandler { + /** @var \AMQPExchange $exchange */ protected $exchange; + /** @var string $space */ protected $space; /** - * @param \AMQPConnection $amqp Amqp connection, ready for use - * @param string $exchange exchange name + * @param \AMQPConnection $amqp AMQP connection, ready for use + * @param string $exchangeName * @param string $space string to be able better manage routing keys * @param int $level * @param bool $bubble Whether the messages that are handled can bubble up the stack or not */ - function __construct(\AMQPConnection $amqp, $exchange = 'log', $space = '', $level = Logger::DEBUG, $bubble = true) + function __construct(\AMQPConnection $amqp, $exchangeName = 'log', $space = '', $level = Logger::DEBUG, $bubble = true) { $this->space = $space; $channel = new \AMQPChannel($amqp); $this->exchange = new \AMQPExchange($channel); - $this->exchange->setName($exchange); + $this->exchange->setName($exchangeName); parent::__construct($level, $bubble); } diff --git a/tests/Monolog/Handler/AmqpHandlerTest.php b/tests/Monolog/Handler/AmqpHandlerTest.php new file mode 100644 index 00000000..efcbc5d8 --- /dev/null +++ b/tests/Monolog/Handler/AmqpHandlerTest.php @@ -0,0 +1,50 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Monolog\Handler; + +use Monolog\TestCase; +use Monolog\Logger; + +/** + * @covers Monolog\Handler\RotatingFileHandler + */ +class RotatingFileHandlerTest extends TestCase +{ + public function setUp() + { + if (!class_exists('AMQPConnection') || !class_exists('AMQPExchange')) { + $this->markTestSkipped("amqp-php not installed"); + } + + if (!class_exists('AMQPChannel')) { + throw new \Exception(' Please update AMQP to version >= 1'); + } + + require_once __DIR__ . '/AmqpMocks.php'; + } + + public function testWrite() + { +// $handler = new AmqpHandler($this->getMockAMQPConnection(), 'log', 'monolog'); + } + + public function getMockAMQPConnection() { + return new MockAMQPConnection(); + } + + public function tearDown() + { + foreach (glob(__DIR__.'/Fixtures/*.rot') as $file) { + unlink($file); + } + } +} \ No newline at end of file diff --git a/tests/Monolog/Handler/AmqpMocks.php b/tests/Monolog/Handler/AmqpMocks.php new file mode 100644 index 00000000..cdbb8a8a --- /dev/null +++ b/tests/Monolog/Handler/AmqpMocks.php @@ -0,0 +1,61 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Monolog\Handler; + +class MockAMQPConnection extends \AMQPConnection +{ + public function __construct(){ + + } + + public function pconnect() + { + return true; + } + + public function reconnect() + { + return false; + } + + public function connect() { + return true; + } + + public function isConnected() { + return true; + } +} + + +class MockAMQPChannel extends \AMQPChannel +{ + public function __construct(MockAMQPConnection $connection) { + + } +} + +class MockAMQPExchange extends \AMQPExchange +{ + + public function __construct(MockAMQPChannel $channel) { + + } + + public function publish($message, $routing_key, $flags, $headers){ + return; + } + + public function setName($exchangeName) { + return true; + } +} \ No newline at end of file From a9df0f461a14cd02b8a1b6425b5360c5145d6e72 Mon Sep 17 00:00:00 2001 From: pomaxa Date: Wed, 13 Jun 2012 12:38:09 +0300 Subject: [PATCH 05/14] test fix --- tests/Monolog/Handler/AmqpHandlerTest.php | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/tests/Monolog/Handler/AmqpHandlerTest.php b/tests/Monolog/Handler/AmqpHandlerTest.php index efcbc5d8..751ce4f0 100644 --- a/tests/Monolog/Handler/AmqpHandlerTest.php +++ b/tests/Monolog/Handler/AmqpHandlerTest.php @@ -17,7 +17,7 @@ use Monolog\Logger; /** * @covers Monolog\Handler\RotatingFileHandler */ -class RotatingFileHandlerTest extends TestCase +class AmqpHandlerTest extends TestCase { public function setUp() { @@ -32,12 +32,20 @@ class RotatingFileHandlerTest extends TestCase require_once __DIR__ . '/AmqpMocks.php'; } - public function testWrite() + + public function testConstruct() { // $handler = new AmqpHandler($this->getMockAMQPConnection(), 'log', 'monolog'); +// $this->assertInstanceOf('Monolog\Handler\AmqpHandler', $handler); } - public function getMockAMQPConnection() { + public function testWrite() + { + + } + + public function getMockAMQPConnection() + { return new MockAMQPConnection(); } From 72ee0aee9627bcaf093be5bfbc84d2abfe3c6518 Mon Sep 17 00:00:00 2001 From: Andrew Tch Date: Wed, 13 Jun 2012 17:10:09 +0300 Subject: [PATCH 06/14] mock implemenation, kind of --- src/Monolog/Handler/AmqpHandler.php | 61 ++++++++++++++++++----- tests/Monolog/Handler/AmqpHandlerTest.php | 51 ++++++++++++++----- tests/Monolog/Handler/AmqpMocks.php | 61 ----------------------- 3 files changed, 87 insertions(+), 86 deletions(-) delete mode 100644 tests/Monolog/Handler/AmqpMocks.php diff --git a/src/Monolog/Handler/AmqpHandler.php b/src/Monolog/Handler/AmqpHandler.php index a3f95244..64ef53b3 100644 --- a/src/Monolog/Handler/AmqpHandler.php +++ b/src/Monolog/Handler/AmqpHandler.php @@ -16,24 +16,33 @@ use Monolog\Formatter\JsonFormatter; class AmqpHandler extends AbstractProcessingHandler { - /** @var \AMQPExchange $exchange */ + /** + * @var \AMQPExchange $exchange + */ protected $exchange; - /** @var string $space */ - protected $space; /** - * @param \AMQPConnection $amqp AMQP connection, ready for use + * Describes current issuer (e.g. "database", "landing", "server" and so on) + * @var string $issuer + */ + protected $issuer; + + /** + * @param \AMQPExchange $exchange AMQP exchange, ready for use * @param string $exchangeName - * @param string $space string to be able better manage routing keys + * @param string $issuer isser name * @param int $level * @param bool $bubble Whether the messages that are handled can bubble up the stack or not */ - function __construct(\AMQPConnection $amqp, $exchangeName = 'log', $space = '', $level = Logger::DEBUG, $bubble = true) + public function __construct($exchange, $exchangeName = 'log', $issuer = 'default', $level = Logger::DEBUG, $bubble = true) { - $this->space = $space; - $channel = new \AMQPChannel($amqp); - $this->exchange = new \AMQPExchange($channel); + if (!$exchange instanceof \AMQPExchange) { + throw new \LogicException('AMQP handler requires a valid exchange to be provided'); + } + + $this->exchange = $exchange; $this->exchange->setName($exchangeName); + parent::__construct($level, $bubble); } @@ -46,9 +55,19 @@ class AmqpHandler extends AbstractProcessingHandler protected function write(array $record) { $data = $record["formatted"]; - $routingKey = substr(strtolower($record['level_name']),0,4 ).'.'.$this->space; - $this->exchange->publish($data, $routingKey, 0, - array('delivery_mode' => 2, 'Content-type' => 'application/json')); + + $routingKey = sprintf('%s.%s', + substr($record['level_name'], 0, 4), + $this->getIssuer()); + + //we do not check return value because no handler really does + $this->exchange->publish($data, + strtolower($routingKey), + 0, + array( + 'delivery_mode' => 2, + 'Content-type' => 'application/json' + )); } /** @@ -58,4 +77,22 @@ class AmqpHandler extends AbstractProcessingHandler { return new JsonFormatter(); } + + /** + * Issuer setter + * @param string $issuer + */ + public function setIssuer($issuer) + { + $this->issuer = $issuer; + } + + /** + * Issuer getter + * @return string + */ + public function getIssuer() + { + return $this->issuer; + } } diff --git a/tests/Monolog/Handler/AmqpHandlerTest.php b/tests/Monolog/Handler/AmqpHandlerTest.php index 751ce4f0..7f9646b5 100644 --- a/tests/Monolog/Handler/AmqpHandlerTest.php +++ b/tests/Monolog/Handler/AmqpHandlerTest.php @@ -28,31 +28,56 @@ class AmqpHandlerTest extends TestCase if (!class_exists('AMQPChannel')) { throw new \Exception(' Please update AMQP to version >= 1'); } - - require_once __DIR__ . '/AmqpMocks.php'; } - - public function testConstruct() + /** + * @covers Monolog\Handler\AmqpHandler::__construct + * @covers Monolog\Handler\AmqpHandler::handle + * @covers Monolog\Handler\AmqpHandler::write + * @covers Monolog\Handler\AmqpHandler::getDefaultFormatter + */ + public function testHandle() { -// $handler = new AmqpHandler($this->getMockAMQPConnection(), 'log', 'monolog'); -// $this->assertInstanceOf('Monolog\Handler\AmqpHandler', $handler); + $exchange = $this->getExchange(); + + $handler = new AmqpHandler($exchange, 'log', 'test'); + + $record = $this->getRecord(Logger::WARNING, 'test', array('data' => new \stdClass, 'foo' => 34)); + + $handler->handle($record); } - public function testWrite() + protected function getExchange() { + /* sorry, but PHP bug in zend_object_store_get_object segfaults + php where using mocks on AMQP classes. should be fixed someday, + but now it's time for some shitcode (see below) + $exchange = $this->getMockBuilder('\AMQPExchange') + ->setConstructorArgs(array($this->getMock('\AMQPChannel'))) + ->setMethods(array('setName')) + ->getMock(); + $exchange->expects($this->any()) + ->method('setName') + ->will($this->returnValue(true)); + */ + return new MockAMQPExchange(); + } +} + +class MockAMQPExchange extends \AMQPExchange +{ + public function __construct() + { } - public function getMockAMQPConnection() + public function publish($message, $routing_key, $params = 0, $attributes = array()) { - return new MockAMQPConnection(); + return true; } - public function tearDown() + public function setName($name) { - foreach (glob(__DIR__.'/Fixtures/*.rot') as $file) { - unlink($file); - } + return true; } } \ No newline at end of file diff --git a/tests/Monolog/Handler/AmqpMocks.php b/tests/Monolog/Handler/AmqpMocks.php deleted file mode 100644 index cdbb8a8a..00000000 --- a/tests/Monolog/Handler/AmqpMocks.php +++ /dev/null @@ -1,61 +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 MockAMQPConnection extends \AMQPConnection -{ - public function __construct(){ - - } - - public function pconnect() - { - return true; - } - - public function reconnect() - { - return false; - } - - public function connect() { - return true; - } - - public function isConnected() { - return true; - } -} - - -class MockAMQPChannel extends \AMQPChannel -{ - public function __construct(MockAMQPConnection $connection) { - - } -} - -class MockAMQPExchange extends \AMQPExchange -{ - - public function __construct(MockAMQPChannel $channel) { - - } - - public function publish($message, $routing_key, $flags, $headers){ - return; - } - - public function setName($exchangeName) { - return true; - } -} \ No newline at end of file From fb19840a8f02ec8025027aa09fb463f530e84ad5 Mon Sep 17 00:00:00 2001 From: pomaxa Date: Wed, 13 Jun 2012 17:36:25 +0300 Subject: [PATCH 07/14] add type hint, remove Exception --- src/Monolog/Handler/AmqpHandler.php | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/Monolog/Handler/AmqpHandler.php b/src/Monolog/Handler/AmqpHandler.php index 64ef53b3..13c7351c 100644 --- a/src/Monolog/Handler/AmqpHandler.php +++ b/src/Monolog/Handler/AmqpHandler.php @@ -34,12 +34,9 @@ class AmqpHandler extends AbstractProcessingHandler * @param int $level * @param bool $bubble Whether the messages that are handled can bubble up the stack or not */ - public function __construct($exchange, $exchangeName = 'log', $issuer = 'default', $level = Logger::DEBUG, $bubble = true) + public function __construct(\AMQPExchange $exchange, $exchangeName = 'log', $issuer = 'default', $level = Logger::DEBUG, $bubble = true) { - if (!$exchange instanceof \AMQPExchange) { - throw new \LogicException('AMQP handler requires a valid exchange to be provided'); - } - + $this->issuer = $issuer; $this->exchange = $exchange; $this->exchange->setName($exchangeName); From 9d8b108d3cf56229c6c304e3e10b26f49fbf5d19 Mon Sep 17 00:00:00 2001 From: pomaxa Date: Wed, 13 Jun 2012 17:51:36 +0300 Subject: [PATCH 08/14] remove notation --- tests/Monolog/Handler/AmqpHandlerTest.php | 6 ------ 1 file changed, 6 deletions(-) diff --git a/tests/Monolog/Handler/AmqpHandlerTest.php b/tests/Monolog/Handler/AmqpHandlerTest.php index 7f9646b5..5a817bcd 100644 --- a/tests/Monolog/Handler/AmqpHandlerTest.php +++ b/tests/Monolog/Handler/AmqpHandlerTest.php @@ -30,12 +30,6 @@ class AmqpHandlerTest extends TestCase } } - /** - * @covers Monolog\Handler\AmqpHandler::__construct - * @covers Monolog\Handler\AmqpHandler::handle - * @covers Monolog\Handler\AmqpHandler::write - * @covers Monolog\Handler\AmqpHandler::getDefaultFormatter - */ public function testHandle() { $exchange = $this->getExchange(); From 6a86fa4444dc34902c6ed1589c5c5006e03394ea Mon Sep 17 00:00:00 2001 From: pomaxa Date: Wed, 13 Jun 2012 17:53:55 +0300 Subject: [PATCH 09/14] skip test instead of throw an error --- tests/Monolog/Handler/AmqpHandlerTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Monolog/Handler/AmqpHandlerTest.php b/tests/Monolog/Handler/AmqpHandlerTest.php index 5a817bcd..e0b11fc5 100644 --- a/tests/Monolog/Handler/AmqpHandlerTest.php +++ b/tests/Monolog/Handler/AmqpHandlerTest.php @@ -26,7 +26,7 @@ class AmqpHandlerTest extends TestCase } if (!class_exists('AMQPChannel')) { - throw new \Exception(' Please update AMQP to version >= 1'); + $this->markTestSkipped("Please update AMQP to version >= 1"); } } From 6b4f4af85f5ccc29807fd4c555cfacbfeae7cc5c Mon Sep 17 00:00:00 2001 From: pomaxa Date: Fri, 15 Jun 2012 13:18:44 +0300 Subject: [PATCH 10/14] get issuer name from record param channel, instead of passing it through handler constructor --- pharIt.php | 28 ++++++++++++++++++++++ src/Monolog/Handler/AmqpHandler.php | 29 ++--------------------- tests/Monolog/Handler/AmqpHandlerTest.php | 2 +- 3 files changed, 31 insertions(+), 28 deletions(-) create mode 100644 pharIt.php diff --git a/pharIt.php b/pharIt.php new file mode 100644 index 00000000..5581328a --- /dev/null +++ b/pharIt.php @@ -0,0 +1,28 @@ +#!/usr/bin/env php +setSignatureAlgorithm(Phar::SHA1); + +$phar->startBuffering(); + +$files = new RecursiveIteratorIterator(new RecursiveDirectoryIterator(__DIR__.'/src/Monolog', FilesystemIterator::CURRENT_AS_FILEINFO | FilesystemIterator::SKIP_DOTS), RecursiveIteratorIterator::CHILD_FIRST); +foreach ($files as $file) { + if (false !== strpos($file->getRealPath(), '.git')) { + continue; + } + + $path = str_replace(realpath(__DIR__).'/', '', $file->getRealPath()); + $phar->addFile($file->getRealPath(), $path); + + echo "$path\n"; +} + +$phar->addFile('src/Monolog/Logger.php'); + +$phar->setDefaultStub('src/Monolog/Logger.php', 'Logger.php'); + +$phar->stopBuffering(); +$phar->compressFiles(Phar::GZ); + +unset($phar); \ No newline at end of file diff --git a/src/Monolog/Handler/AmqpHandler.php b/src/Monolog/Handler/AmqpHandler.php index 13c7351c..f34e11b4 100644 --- a/src/Monolog/Handler/AmqpHandler.php +++ b/src/Monolog/Handler/AmqpHandler.php @@ -21,12 +21,6 @@ class AmqpHandler extends AbstractProcessingHandler */ protected $exchange; - /** - * Describes current issuer (e.g. "database", "landing", "server" and so on) - * @var string $issuer - */ - protected $issuer; - /** * @param \AMQPExchange $exchange AMQP exchange, ready for use * @param string $exchangeName @@ -34,9 +28,8 @@ class AmqpHandler extends AbstractProcessingHandler * @param int $level * @param bool $bubble Whether the messages that are handled can bubble up the stack or not */ - public function __construct(\AMQPExchange $exchange, $exchangeName = 'log', $issuer = 'default', $level = Logger::DEBUG, $bubble = true) + public function __construct(\AMQPExchange $exchange, $exchangeName = 'log', $level = Logger::DEBUG, $bubble = true) { - $this->issuer = $issuer; $this->exchange = $exchange; $this->exchange->setName($exchangeName); @@ -55,7 +48,7 @@ class AmqpHandler extends AbstractProcessingHandler $routingKey = sprintf('%s.%s', substr($record['level_name'], 0, 4), - $this->getIssuer()); + $record['channel']); //we do not check return value because no handler really does $this->exchange->publish($data, @@ -74,22 +67,4 @@ class AmqpHandler extends AbstractProcessingHandler { return new JsonFormatter(); } - - /** - * Issuer setter - * @param string $issuer - */ - public function setIssuer($issuer) - { - $this->issuer = $issuer; - } - - /** - * Issuer getter - * @return string - */ - public function getIssuer() - { - return $this->issuer; - } } diff --git a/tests/Monolog/Handler/AmqpHandlerTest.php b/tests/Monolog/Handler/AmqpHandlerTest.php index e0b11fc5..780624da 100644 --- a/tests/Monolog/Handler/AmqpHandlerTest.php +++ b/tests/Monolog/Handler/AmqpHandlerTest.php @@ -34,7 +34,7 @@ class AmqpHandlerTest extends TestCase { $exchange = $this->getExchange(); - $handler = new AmqpHandler($exchange, 'log', 'test'); + $handler = new AmqpHandler($exchange, 'log'); $record = $this->getRecord(Logger::WARNING, 'test', array('data' => new \stdClass, 'foo' => 34)); From 246ea3a9f621c882e5bd28914e458da06d09f72d Mon Sep 17 00:00:00 2001 From: pomaxa Date: Fri, 15 Jun 2012 13:19:12 +0300 Subject: [PATCH 11/14] typo --- pharIt.php | 28 ---------------------------- 1 file changed, 28 deletions(-) delete mode 100644 pharIt.php diff --git a/pharIt.php b/pharIt.php deleted file mode 100644 index 5581328a..00000000 --- a/pharIt.php +++ /dev/null @@ -1,28 +0,0 @@ -#!/usr/bin/env php -setSignatureAlgorithm(Phar::SHA1); - -$phar->startBuffering(); - -$files = new RecursiveIteratorIterator(new RecursiveDirectoryIterator(__DIR__.'/src/Monolog', FilesystemIterator::CURRENT_AS_FILEINFO | FilesystemIterator::SKIP_DOTS), RecursiveIteratorIterator::CHILD_FIRST); -foreach ($files as $file) { - if (false !== strpos($file->getRealPath(), '.git')) { - continue; - } - - $path = str_replace(realpath(__DIR__).'/', '', $file->getRealPath()); - $phar->addFile($file->getRealPath(), $path); - - echo "$path\n"; -} - -$phar->addFile('src/Monolog/Logger.php'); - -$phar->setDefaultStub('src/Monolog/Logger.php', 'Logger.php'); - -$phar->stopBuffering(); -$phar->compressFiles(Phar::GZ); - -unset($phar); \ No newline at end of file From 0932fd33c4d8c6866a7041b235cfc80352964077 Mon Sep 17 00:00:00 2001 From: pomaxa Date: Fri, 15 Jun 2012 14:31:50 +0300 Subject: [PATCH 12/14] comments & readme update --- README.mdown | 4 ++++ src/Monolog/Handler/AmqpHandler.php | 5 +---- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/README.mdown b/README.mdown index dd87e66b..a2c419a9 100644 --- a/README.mdown +++ b/README.mdown @@ -104,6 +104,9 @@ Handlers - _GelfHandler_: Logs records to a [Graylog2](http://www.graylog2.org) server. - _SocketHandler_: Logs records to [sockets](http://php.net/fsockopen), use this for UNIX and TCP sockets. See an [example](https://github.com/Seldaek/monolog/blob/master/doc/sockets.md). +- _AmqpHandler_L Logs records using [amqp](php.net/manual/en/book.amqp.php) protocol to the RabbitMQ server. + Note: handler needs an installed amqp version > 1. + For instructions on installation look in (http://lv.php.net/manual/en/amqp.installation.php) Wrappers / Special Handlers --------------------------- @@ -154,6 +157,7 @@ Requirements - Any flavor of PHP 5.3 should do - [optional] PHPUnit 3.5+ to execute the test suite (phpunit --version) +- [optional] installed amqp library to use AmqpHandler. Submitting bugs and feature requests ------------------------------------ diff --git a/src/Monolog/Handler/AmqpHandler.php b/src/Monolog/Handler/AmqpHandler.php index f34e11b4..7c8af90e 100644 --- a/src/Monolog/Handler/AmqpHandler.php +++ b/src/Monolog/Handler/AmqpHandler.php @@ -37,10 +37,7 @@ class AmqpHandler extends AbstractProcessingHandler } /** - * Writes the record down to the log of the implementing handler - * - * @param array $record - * @return void + * {@inheritDoc} */ protected function write(array $record) { From 792634384ab5f1ddd06dd374b5479c5924e46010 Mon Sep 17 00:00:00 2001 From: pomaxa Date: Fri, 15 Jun 2012 14:48:07 +0300 Subject: [PATCH 13/14] AMQP mock object --- tests/Monolog/Handler/AmqpExchangeMock.php | 28 ++++++++++++++++++++++ tests/Monolog/Handler/AmqpHandlerTest.php | 18 +------------- 2 files changed, 29 insertions(+), 17 deletions(-) create mode 100644 tests/Monolog/Handler/AmqpExchangeMock.php diff --git a/tests/Monolog/Handler/AmqpExchangeMock.php b/tests/Monolog/Handler/AmqpExchangeMock.php new file mode 100644 index 00000000..690ba078 --- /dev/null +++ b/tests/Monolog/Handler/AmqpExchangeMock.php @@ -0,0 +1,28 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ +namespace Monolog\Handler; + +class MockAMQPExchange extends \AMQPExchange +{ +public function __construct() +{ +} + +public function publish($message, $routing_key, $params = 0, $attributes = array()) +{ +return true; +} + +public function setName($name) +{ +return true; +} +} \ No newline at end of file diff --git a/tests/Monolog/Handler/AmqpHandlerTest.php b/tests/Monolog/Handler/AmqpHandlerTest.php index 780624da..201da5cc 100644 --- a/tests/Monolog/Handler/AmqpHandlerTest.php +++ b/tests/Monolog/Handler/AmqpHandlerTest.php @@ -13,6 +13,7 @@ namespace Monolog\Handler; use Monolog\TestCase; use Monolog\Logger; +use Monolog\Handler\MockAMQPExchange; /** * @covers Monolog\Handler\RotatingFileHandler @@ -57,21 +58,4 @@ class AmqpHandlerTest extends TestCase */ return new MockAMQPExchange(); } -} - -class MockAMQPExchange extends \AMQPExchange -{ - public function __construct() - { - } - - public function publish($message, $routing_key, $params = 0, $attributes = array()) - { - return true; - } - - public function setName($name) - { - return true; - } } \ No newline at end of file From e5ffccd4221f91f3d7c32075f08d98cb60a59dc1 Mon Sep 17 00:00:00 2001 From: pomaxa Date: Fri, 15 Jun 2012 17:56:19 +0300 Subject: [PATCH 14/14] fix indentation --- tests/Monolog/Handler/AmqpExchangeMock.php | 23 +++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/tests/Monolog/Handler/AmqpExchangeMock.php b/tests/Monolog/Handler/AmqpExchangeMock.php index 690ba078..2ed311ea 100644 --- a/tests/Monolog/Handler/AmqpExchangeMock.php +++ b/tests/Monolog/Handler/AmqpExchangeMock.php @@ -8,21 +8,22 @@ * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ + namespace Monolog\Handler; class MockAMQPExchange extends \AMQPExchange { -public function __construct() -{ -} + public function __construct() + { + } -public function publish($message, $routing_key, $params = 0, $attributes = array()) -{ -return true; -} + public function publish($message, $routing_key, $params = 0, $attributes = array()) + { + return true; + } -public function setName($name) -{ -return true; -} + public function setName($name) + { + return true; + } } \ No newline at end of file