scratch – Blame information for rev 122
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
120 | office | 1 | <?php |
2 | |||
3 | /* |
||
4 | * This file is part of the Monolog package. |
||
5 | * |
||
6 | * (c) Jordi Boggiano <j.boggiano@seld.be> |
||
7 | * |
||
8 | * For the full copyright and license information, please view the LICENSE |
||
9 | * file that was distributed with this source code. |
||
10 | */ |
||
11 | |||
12 | namespace Monolog\Formatter; |
||
13 | |||
14 | use Monolog\Logger; |
||
15 | |||
16 | /** |
||
17 | * Formats a log message according to the ChromePHP array format |
||
18 | * |
||
19 | * @author Christophe Coevoet <stof@notk.org> |
||
20 | */ |
||
21 | class ChromePHPFormatter implements FormatterInterface |
||
22 | { |
||
23 | /** |
||
24 | * Translates Monolog log levels to Wildfire levels. |
||
25 | */ |
||
26 | private $logLevels = array( |
||
27 | Logger::DEBUG => 'log', |
||
28 | Logger::INFO => 'info', |
||
29 | Logger::NOTICE => 'info', |
||
30 | Logger::WARNING => 'warn', |
||
31 | Logger::ERROR => 'error', |
||
32 | Logger::CRITICAL => 'error', |
||
33 | Logger::ALERT => 'error', |
||
34 | Logger::EMERGENCY => 'error', |
||
35 | ); |
||
36 | |||
37 | /** |
||
38 | * {@inheritdoc} |
||
39 | */ |
||
40 | public function format(array $record) |
||
41 | { |
||
42 | // Retrieve the line and file if set and remove them from the formatted extra |
||
43 | $backtrace = 'unknown'; |
||
44 | if (isset($record['extra']['file'], $record['extra']['line'])) { |
||
45 | $backtrace = $record['extra']['file'].' : '.$record['extra']['line']; |
||
46 | unset($record['extra']['file'], $record['extra']['line']); |
||
47 | } |
||
48 | |||
49 | $message = array('message' => $record['message']); |
||
50 | if ($record['context']) { |
||
51 | $message['context'] = $record['context']; |
||
52 | } |
||
53 | if ($record['extra']) { |
||
54 | $message['extra'] = $record['extra']; |
||
55 | } |
||
56 | if (count($message) === 1) { |
||
57 | $message = reset($message); |
||
58 | } |
||
59 | |||
60 | return array( |
||
61 | $record['channel'], |
||
62 | $message, |
||
63 | $backtrace, |
||
64 | $this->logLevels[$record['level']], |
||
65 | ); |
||
66 | } |
||
67 | |||
68 | public function formatBatch(array $records) |
||
69 | { |
||
70 | $formatted = array(); |
||
71 | |||
72 | foreach ($records as $record) { |
||
73 | $formatted[] = $this->format($record); |
||
74 | } |
||
75 | |||
76 | return $formatted; |
||
77 | } |
||
78 | } |