ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
WildfireFormatter.php
Go to the documentation of this file.
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
12namespace Monolog\Formatter;
13
15
24{
25 const TABLE = 'table';
26
30 private $logLevels = array(
31 Logger::DEBUG => 'LOG',
32 Logger::INFO => 'INFO',
33 Logger::NOTICE => 'INFO',
34 Logger::WARNING => 'WARN',
35 Logger::ERROR => 'ERROR',
36 Logger::CRITICAL => 'ERROR',
37 Logger::ALERT => 'ERROR',
38 Logger::EMERGENCY => 'ERROR',
39 );
40
44 public function format(array $record)
45 {
46 // Retrieve the line and file if set and remove them from the formatted extra
47 $file = $line = '';
48 if (isset($record['extra']['file'])) {
49 $file = $record['extra']['file'];
50 unset($record['extra']['file']);
51 }
52 if (isset($record['extra']['line'])) {
53 $line = $record['extra']['line'];
54 unset($record['extra']['line']);
55 }
56
57 $record = $this->normalize($record);
58 $message = array('message' => $record['message']);
59 $handleError = false;
60 if ($record['context']) {
61 $message['context'] = $record['context'];
62 $handleError = true;
63 }
64 if ($record['extra']) {
65 $message['extra'] = $record['extra'];
66 $handleError = true;
67 }
68 if (count($message) === 1) {
69 $message = reset($message);
70 }
71
72 if (isset($record['context'][self::TABLE])) {
73 $type = 'TABLE';
74 $label = $record['channel'] .': '. $record['message'];
75 $message = $record['context'][self::TABLE];
76 } else {
77 $type = $this->logLevels[$record['level']];
78 $label = $record['channel'];
79 }
80
81 // Create JSON object describing the appearance of the message in the console
82 $json = $this->toJson(array(
83 array(
84 'Type' => $type,
85 'File' => $file,
86 'Line' => $line,
87 'Label' => $label,
88 ),
89 $message,
90 ), $handleError);
91
92 // The message itself is a serialization of the above JSON object + it's length
93 return sprintf(
94 '%s|%s|',
95 strlen($json),
96 $json
97 );
98 }
99
100 public function formatBatch(array $records)
101 {
102 throw new \BadMethodCallException('Batch formatting does not make sense for the WildfireFormatter');
103 }
104
105 protected function normalize($data)
106 {
107 if (is_object($data) && !$data instanceof \DateTime) {
108 return $data;
109 }
110
111 return parent::normalize($data);
112 }
113}
print $file
Normalizes incoming records to remove objects/resources so it's easier to dump to various targets.
Serializes a log message according to Wildfire's header requirements.
formatBatch(array $records)
{{Formats a set of log records.mixed The formatted set of records}}
format(array $record)
{{Formats a log record.mixed The formatted record}}
$logLevels
Translates Monolog log levels to Wildfire levels.
Monolog log channel.
Definition: Logger.php:28
const EMERGENCY
Urgent alert.
Definition: Logger.php:77
const ERROR
Runtime errors.
Definition: Logger.php:57
const CRITICAL
Critical conditions.
Definition: Logger.php:64
const WARNING
Exceptional occurrences that are not errors.
Definition: Logger.php:52
const INFO
Interesting events.
Definition: Logger.php:39
const DEBUG
Detailed debug information.
Definition: Logger.php:32
const NOTICE
Uncommon events.
Definition: Logger.php:44
const ALERT
Action must be taken immediately.
Definition: Logger.php:72
$data
$records
Definition: simple_test.php:17