public function testLogInterpolateMutiple() { $logger = new Resque_Log(); $actual = $logger->interpolate('string {replace1} {replace2}', array('replace1' => 'value1', 'replace2' => 'value2')); $expected = 'string value1 value2'; $this->assertEquals($expected, $actual); }
/** * 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()) { parent::log($level, $message, $context); // if we have a stack context which is the Exception that was thrown, // send that to SS_Log so writers can use that for reporting the error. if (!empty($context['stack'])) { SS_Log::log($context['stack'], $this->convertLevel($level)); } }
/** * 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) { if (!file_exists($this->filePath)) { parent::log($level, $message, $context); return; } file_put_contents($this->filePath, '[' . $level . '] [' . strftime('%T %Y-%m-%d') . '] ' . $this->interpolate($message, $context) . PHP_EOL, FILE_APPEND); return; } if (!($level === \Psr\Log\LogLevel::INFO || $level === \Psr\Log\LogLevel::DEBUG)) { if (!file_exists($this->filePath)) { parent::log($level, $message, $context); return; } file_put_contents($this->filePath, '[' . $level . '] ' . $this->interpolate($message, $context) . PHP_EOL, FILE_APPEND); return; } }
/** * Inject the logging object into the worker * * @param Psr\Log\LoggerInterface $logger */ public function setLogger(Psr\Log\LoggerInterface $logger) { $this->logger->setLogger($logger); }