diff --git a/.gitmodules b/.gitmodules index 1fb4a04d..2a2dfe9a 100644 --- a/.gitmodules +++ b/.gitmodules @@ -4,3 +4,6 @@ [submodule "vendor/Doctrine"] path = vendor/Doctrine url = https://github.com/doctrine/common +[submodule "vendor/Monolog"] + path = vendor/Monolog + url = https://github.com/Seldaek/monolog.git diff --git a/src/Guzzle/Common/Log/MonologLogAdapter.php b/src/Guzzle/Common/Log/MonologLogAdapter.php new file mode 100644 index 00000000..85f70288 --- /dev/null +++ b/src/Guzzle/Common/Log/MonologLogAdapter.php @@ -0,0 +1,45 @@ + + * @license See the LICENSE file that was distributed with this source code. + */ + +namespace Guzzle\Common\Log; + +use Monolog\Logger; + +/** + * Monolog log adapter + * + * @author Michael Dowling + * @link https://github.com/Seldaek/monolog + */ +class MonologLogAdapter extends AbstractLogAdapter +{ + /** + * Adapt a Monolog Logger object + * + * @param Logger $logObject Log object to adapt + * @throws InvalidArgumentException + */ + public function __construct($logObject) + { + if (!($logObject instanceof Logger)) { + throw new \InvalidArgumentException( + 'Object must be an instance of Monolog\Logger' + ); + } + + $this->log = $logObject; + } + + /** + * {@inheritdoc} + */ + public function log($message, $priority = LOG_INFO, $extras = null) + { + $this->log->addRecord($priority, $message); + + return $this; + } +} \ No newline at end of file diff --git a/src/Guzzle/Common/Log/ZendLogAdapter.php b/src/Guzzle/Common/Log/ZendLogAdapter.php index d0811101..76b5c774 100644 --- a/src/Guzzle/Common/Log/ZendLogAdapter.php +++ b/src/Guzzle/Common/Log/ZendLogAdapter.php @@ -33,7 +33,7 @@ class ZendLogAdapter extends AbstractLogAdapter /** * {@inheritdoc} */ - public function log($message, $priority = self::INFO, $extras = null) + public function log($message, $priority = LOG_INFO, $extras = null) { $this->log->log($message, $priority, $extras); diff --git a/tests/Guzzle/Tests/Common/Log/MonologLogAdapterTest.php b/tests/Guzzle/Tests/Common/Log/MonologLogAdapterTest.php new file mode 100644 index 00000000..08e78828 --- /dev/null +++ b/tests/Guzzle/Tests/Common/Log/MonologLogAdapterTest.php @@ -0,0 +1,47 @@ + + * @license See the LICENSE file that was distributed with this source code. + */ + +namespace Guzzle\Tests\Common\Log; + +use Guzzle\Common\Log\MonologLogAdapter; +use Monolog\Logger; +use Monolog\Handler\TestHandler; + +/** + * @author Michael Dowling + */ +class MonologLogAdapterTest extends \Guzzle\Tests\GuzzleTestCase +{ + /** + * @covers Guzzle\Common\Log\MonologLogAdapter::__construct + * @expectedException InvalidArgumentException + */ + public function testEnforcesType() + { + // A successful construction + $log = new Logger('test'); + $log->pushHandler(new TestHandler()); + $adapter = new MonologLogAdapter($log); + + // Throws an exception + $this->adapter = new MonologLogAdapter(new \stdClass()); + } + + /** + * @covers Guzzle\Common\Log\MonologLogAdapter::log + */ + public function testLogsMessagesToAdaptedObject() + { + $log = new Logger('test'); + $handler = new TestHandler(); + $log->pushHandler($handler); + $adapter = new MonologLogAdapter($log); + + $adapter->log('test!', Logger::INFO); + + $this->assertTrue($handler->hasInfoRecords()); + } +} diff --git a/tests/Guzzle/Tests/Common/Log/ZendLogAdapterTest.php b/tests/Guzzle/Tests/Common/Log/ZendLogAdapterTest.php index c93b0795..87db8e19 100644 --- a/tests/Guzzle/Tests/Common/Log/ZendLogAdapterTest.php +++ b/tests/Guzzle/Tests/Common/Log/ZendLogAdapterTest.php @@ -37,27 +37,12 @@ class ZendLogAdapterTest extends \Guzzle\Tests\GuzzleTestCase $this->adapter = new ZendLogAdapter($this->log); } - /** - * Check for the existence of the Zend_Framework in your path - */ - protected function zfSkip() - { - if (!class_exists('\Zend_Log')) { - $this->markTestSkipped( - 'The Zend Framework is not present in your path' - ); - return; - } - } - /** * @covers Guzzle\Common\Log\AbstractLogAdapter::__construct * @expectedException InvalidArgumentException */ - public function testConstruct() + public function testEnforcesType() { - $this->zfSkip(); - // A successful construction $this->adapter = new ZendLogAdapter($this->log, new Collection()); @@ -71,8 +56,6 @@ class ZendLogAdapterTest extends \Guzzle\Tests\GuzzleTestCase */ public function testLogsMessagesToAdaptedObject() { - $this->zfSkip(); - // Test without a priority $this->adapter->log('test', \LOG_NOTICE, 'guzzle.common.log.adapter.zend_log_adapter', 'localhost'); $this->assertEquals(1, substr_count(ob_get_contents(), 'test')); @@ -87,8 +70,6 @@ class ZendLogAdapterTest extends \Guzzle\Tests\GuzzleTestCase */ public function testExposesAdaptedLogObject() { - $this->zfSkip(); - $this->assertEquals($this->log, $this->adapter->getLogObject()); } } \ No newline at end of file diff --git a/tests/bootstrap.php b/tests/bootstrap.php index baf6ff60..132a4150 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -17,7 +17,8 @@ $classLoader = new \Symfony\Component\ClassLoader\UniversalClassLoader(); $classLoader->registerNamespaces(array( 'Guzzle\Tests' => __DIR__, 'Guzzle' => __DIR__ . '/../src', - 'Doctrine' => __DIR__ . '/../vendor/Doctrine/lib' + 'Doctrine' => __DIR__ . '/../vendor/Doctrine/lib', + 'Monolog' => __DIR__ . '/../vendor/Monolog/src' )); $classLoader->registerPrefix('Zend_', __DIR__ . '/../vendor'); diff --git a/vendor/Monolog b/vendor/Monolog new file mode 160000 index 00000000..ea466fa8 --- /dev/null +++ b/vendor/Monolog @@ -0,0 +1 @@ +Subproject commit ea466fa84863ef15e5dd178d14a804a1efbfd07a