/** * {@inheritdoc} */ public function handle(array $record) { $message = Logger::interpolate($record['message'], $record['context']); if ($record['level'] != LogLevel::INFO) { $message = '[' . $record['level'] . '] ' . $message; } if (Logger::compare($record['level'], LogLevel::ERROR) >= 0) { $this->shell->error($message); } else { $this->shell->put($message); } }
public function testInterpolate() { $this->assertEquals('foo bar', Logger::interpolate('{a} {b}', ['a' => 'foo', 'b' => 'bar'])); $this->assertEquals('foo {b}', Logger::interpolate('{a} {b}', ['a' => 'foo'])); }
/** * Format a log message for a log file. * * @param array $record * Log message array. * @return string Formatted log message followed by a line break. */ public static function format(array $record) { $seconds = (int) $record['time']; $millis = floor(($record['time'] - $seconds) * 1000); $timestamp = date('Y-m-d H:i:s', $seconds); $timestamp .= sprintf('.%03d ', $millis); $timestamp .= date('P'); $level = '[' . $record['level'] . ']'; $message = ''; $message .= Logger::interpolate($record['message'], $record['context']); if (isset($record['context']['file'])) { $message .= ' in ' . $record['context']['file']; } if (isset($record['context']['line'])) { $message .= ' on line ' . $record['context']['line']; } return $timestamp . ' ' . $level . ' ' . $message . PHP_EOL; }