ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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 
12 namespace Monolog\Formatter;
13 
14 use Monolog\Logger;
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 }
const NOTICE
Uncommon events.
Definition: Logger.php:44
const DEBUG
Detailed debug information.
Definition: Logger.php:32
const ERROR
Runtime errors.
Definition: Logger.php:57
formatBatch(array $records)
Formats a set of log records.
$type
$logLevels
Translates Monolog log levels to Wildfire levels.
$records
Definition: simple_test.php:22
catch(Exception $e) $message
const WARNING
Exceptional occurrences that are not errors.
Definition: Logger.php:52
Normalizes incoming records to remove objects/resources so it&#39;s easier to dump to various targets...
const EMERGENCY
Urgent alert.
Definition: Logger.php:77
Create styles array
The data for the language used.
const CRITICAL
Critical conditions.
Definition: Logger.php:64
toJson($data, $ignoreErrors=false)
Return the JSON representation of a value.
const ALERT
Action must be taken immediately.
Definition: Logger.php:72
if(!file_exists("$old.txt")) if($old===$new) if(file_exists("$new.txt")) $file
Serializes a log message according to Wildfire&#39;s header requirements.
format(array $record)
{Formats a log record.A record to format mixed The formatted record}
const INFO
Interesting events.
Definition: Logger.php:39