diff --git a/bin/resque b/bin/resque index c0901ce..03d82dc 100755 --- a/bin/resque +++ b/bin/resque @@ -68,9 +68,10 @@ if($APP_INCLUDE) { } // See if the APP_INCLUDE containes a logger object, -// If none exists, fallback to internal logger +// If none exists, use the NullLogger instead, which +// effectively disables logging. if (!isset($logger) || !is_object($logger)) { - $logger = new \Resque\Logger($logLevel); + $logger = new \Psr\Log\NullLogger(); } $BLOCKING = getenv('BLOCKING') !== FALSE; diff --git a/composer.json b/composer.json index c8b0de1..0b4c7d3 100644 --- a/composer.json +++ b/composer.json @@ -30,7 +30,7 @@ "require": { "php": ">=5.6.0", "colinmollenhour/credis": "~1.7", - "psr/log": "~1.0" + "psr/log": ">=1.1.0" }, "suggest": { "ext-pcntl": "REQUIRED for forking processes on platforms that support it (so anything but Windows).", diff --git a/lib/Logger.php b/lib/Logger.php deleted file mode 100644 index 156cb60..0000000 --- a/lib/Logger.php +++ /dev/null @@ -1,69 +0,0 @@ - - * @license http://www.opensource.org/licenses/mit-license.php - */ -class Logger extends AbstractLogger -{ - public $verbose; - - public function __construct($verbose = false) - { - $this->verbose = $verbose; - } - - /** - * Logs with an arbitrary level. - * - * @param mixed $level PSR-3 log level constant, or equivalent string - * @param string $message Message to log, may contain a { placeholder } - * @param array $context Variables to replace { placeholder } - * @return null - */ - public function log($level, $message, array $context = array()) - { - if ($this->verbose) { - fwrite( - STDOUT, - '[' . $level . '] [' . date('H:i:s Y-m-d') . '] ' . $this->interpolate($message, $context) . PHP_EOL - ); - return; - } - - if (!($level === LogLevel::INFO || $level === LogLevel::DEBUG)) { - fwrite( - STDOUT, - '[' . $level . '] ' . $this->interpolate($message, $context) . PHP_EOL - ); - } - } - - /** - * Fill placeholders with the provided context - * @author Jordi Boggiano j.boggiano@seld.be - * - * @param string $message Message to be logged - * @param array $context Array of variables to use in message - * @return string - */ - public function interpolate($message, array $context = array()) - { - // build a replacement array with braces around the context keys - $replace = array(); - foreach ($context as $key => $val) { - $replace['{' . $key . '}'] = $val; - } - - // interpolate replacement values into the message and return - return strtr($message, $replace); - } -} diff --git a/lib/Worker/ResqueWorker.php b/lib/Worker/ResqueWorker.php index 9528c4f..d400f72 100644 --- a/lib/Worker/ResqueWorker.php +++ b/lib/Worker/ResqueWorker.php @@ -4,10 +4,10 @@ namespace Resque\Worker; -use Resque\Logger; use Resque\Resque; use CredisException; use Psr\Log\LogLevel; +use Psr\Log\NullLogger; use Resque\Job\PID; use Resque\Event; use Resque\Exceptions\DirtyExitException; @@ -91,7 +91,7 @@ class ResqueWorker */ public function __construct($queues) { - $this->logger = new Logger(); + $this->logger = new NullLogger(); if (!is_array($queues)) { $queues = array($queues); diff --git a/test/Resque/Tests/LoggerTest.php b/test/Resque/Tests/LoggerTest.php deleted file mode 100644 index 860af25..0000000 --- a/test/Resque/Tests/LoggerTest.php +++ /dev/null @@ -1,36 +0,0 @@ - - * @license http://www.opensource.org/licenses/mit-license.php - */ -class LoggerTest extends ResqueTestCase -{ - public function testLogInterpolate() - { - $logger = new Logger(); - $actual = $logger->interpolate('string {replace}', array('replace' => 'value')); - $expected = 'string value'; - - $this->assertEquals($expected, $actual); - } - - public function testLogInterpolateMutiple() - { - $logger = new Logger(); - $actual = $logger->interpolate( - 'string {replace1} {replace2}', - array('replace1' => 'value1', 'replace2' => 'value2') - ); - $expected = 'string value1 value2'; - - $this->assertEquals($expected, $actual); - } -}