diff --git a/src/Presque/Log/AbstractLogAdapter.php b/src/Presque/Log/AbstractLogAdapter.php new file mode 100644 index 0000000..9d1d475 --- /dev/null +++ b/src/Presque/Log/AbstractLogAdapter.php @@ -0,0 +1,84 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Presque\Log; + +/** + * Abstract log adapter for Presque + */ +abstract class AbstractLogAdapter implements LoggerInterface +{ + protected $log; + + /** + * {@inheritDoc} + */ + public function emerg($message, array $context = array()) + { + $this->log->emerg($message, $context); + } + + /** + * {@inheritDoc} + */ + public function alert($message, array $context = array()) + { + $this->log->alert($message, $context); + } + + /** + * {@inheritDoc} + */ + public function crit($message, array $context = array()) + { + $this->log->crit($message, $context); + } + + /** + * {@inheritDoc} + */ + public function err($message, array $context = array()) + { + $this->log->err($message, $context); + } + + /** + * {@inheritDoc} + */ + public function warn($message, array $context = array()) + { + $this->log->warn($message, $context); + } + + /** + * {@inheritDoc} + */ + public function notice($message, array $context = array()) + { + $this->log->notice($message, $context); + } + + /** + * {@inheritDoc} + */ + public function info($message, array $context = array()) + { + $this->log->info($message, $context); + } + + /** + * {@inheritDoc} + */ + public function debug($message, array $context = array()) + { + $this->log->debug($message, $context); + } +} \ No newline at end of file diff --git a/src/Presque/Log/LoggerInterface.php b/src/Presque/Log/LoggerInterface.php index 3539b3b..9267f0a 100644 --- a/src/Presque/Log/LoggerInterface.php +++ b/src/Presque/Log/LoggerInterface.php @@ -11,7 +11,48 @@ namespace Presque\Log; +/** + * Simple log adapter interface + */ interface LoggerInterface { - function log($message, $priority = LOG_INFO, $extra = null); + /** + * @api + */ + function emerg($message, array $context = array()); + + /** + * @api + */ + function alert($message, array $context = array()); + + /** + * @api + */ + function crit($message, array $context = array()); + + /** + * @api + */ + function err($message, array $context = array()); + + /** + * @api + */ + function warn($message, array $context = array()); + + /** + * @api + */ + function notice($message, array $context = array()); + + /** + * @api + */ + function info($message, array $context = array()); + + /** + * @api + */ + function debug($message, array $context = array()); } \ No newline at end of file diff --git a/src/Presque/Log/MonologLogAdapter.php b/src/Presque/Log/MonologLogAdapter.php index 30eb297..347e3f6 100644 --- a/src/Presque/Log/MonologLogAdapter.php +++ b/src/Presque/Log/MonologLogAdapter.php @@ -16,23 +16,10 @@ /** * Log adapter for Monolog * - * @link https://github.com/guzzle/guzzle/blob/master/src/Guzzle/Common/Log/MonologLogAdapter.php * @link https://github.com/Seldaek/monolog */ -class MonologLogAdapter implements LoggerInterface +class MonologLogAdapter extends AbstractLogAdapter { - /** - * syslog to Monolog mappings - */ - private static $mapping = array( - LOG_DEBUG => Logger::DEBUG, - LOG_INFO => Logger::INFO, - LOG_WARNING => Logger::WARNING, - LOG_ERR => Logger::ERROR, - LOG_CRIT => Logger::CRITICAL, - LOG_ALERT => Logger::ALERT - ); - /** * {@inheritdoc} */ @@ -40,12 +27,4 @@ public function __construct(Logger $logObject) { $this->log = $logObject; } - - /** - * {@inheritdoc} - */ - public function log($message, $priority = LOG_INFO, $extras = null) - { - $this->log->addRecord(self::$mapping[$priority], $message); - } } \ No newline at end of file diff --git a/src/Presque/Log/SymfonyLogAdapter.php b/src/Presque/Log/SymfonyLogAdapter.php new file mode 100644 index 0000000..fa7ed11 --- /dev/null +++ b/src/Presque/Log/SymfonyLogAdapter.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 Presque\Log; + +use Symfony\Component\HttpKernel\Log\LoggerInterface as SymfonyLoggerInterface; + +/** + * Symfony HttpKernel LoggerInterface adapter + */ +class SymfonyLogAdapter extends AbstractLogAdapter +{ + /** + * {@inheritdoc} + */ + public function __construct(SymfonyLoggerInterface $logObject) + { + $this->log = $logObject; + } +} \ No newline at end of file diff --git a/src/Presque/Worker/Worker.php b/src/Presque/Worker/Worker.php index 494ea5e..84280b0 100644 --- a/src/Presque/Worker/Worker.php +++ b/src/Presque/Worker/Worker.php @@ -111,10 +111,7 @@ protected function process(QueueInterface $queue) } if ($this->hasLogger()) { - $this->logger->log( - sprintf('Starting job "%s"', $job), - LOG_DEBUG - ); + $this->logger->debug(sprintf('Starting job "%s"', $job)); } $job->prepare(); diff --git a/tests/Presque/Tests/Worker/WorkerTest.php b/tests/Presque/Tests/Worker/WorkerTest.php index c196a0b..75bd514 100644 --- a/tests/Presque/Tests/Worker/WorkerTest.php +++ b/tests/Presque/Tests/Worker/WorkerTest.php @@ -153,7 +153,7 @@ public function testLoggingJobActivity() $worker->setLogger($logger); $logger - ->shouldReceive('log')->once()->with('Starting job "Presque\Tests\Jobs\SimpleJob"', LOG_DEBUG); + ->shouldReceive('debug')->once()->with('Starting job "Presque\Tests\Jobs\SimpleJob"'); $queue ->shouldReceive('reserve')->once()->andReturn($job);