ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
HtmlFormatter.php
Go to the documentation of this file.
1<?php
2/*
3 * This file is part of the Monolog package.
4 *
5 * (c) Jordi Boggiano <j.boggiano@seld.be>
6 *
7 * For the full copyright and license information, please view the LICENSE
8 * file that was distributed with this source code.
9 */
10
11namespace Monolog\Formatter;
12
14
23{
27 private $logLevels = array(
28 Logger::DEBUG => '#cccccc',
29 Logger::INFO => '#468847',
30 Logger::NOTICE => '#3a87ad',
31 Logger::WARNING => '#c09853',
32 Logger::ERROR => '#f0ad4e',
33 Logger::CRITICAL => '#FF7708',
34 Logger::ALERT => '#C12A19',
35 Logger::EMERGENCY => '#000000',
36 );
37
41 public function __construct($dateFormat = null)
42 {
43 parent::__construct($dateFormat);
44 }
45
54 private function addRow($th, $td = ' ', $escapeTd = true)
55 {
56 $th = htmlspecialchars($th, ENT_NOQUOTES, 'UTF-8');
57 if ($escapeTd) {
58 $td = '<pre>'.htmlspecialchars($td, ENT_NOQUOTES, 'UTF-8').'</pre>';
59 }
60
61 return "<tr style=\"padding: 4px;spacing: 0;text-align: left;\">\n<th style=\"background: #cccccc\" width=\"100px\">$th:</th>\n<td style=\"padding: 4px;spacing: 0;text-align: left;background: #eeeeee\">".$td."</td>\n</tr>";
62 }
63
71 private function addTitle($title, $level)
72 {
73 $title = htmlspecialchars($title, ENT_NOQUOTES, 'UTF-8');
74
75 return '<h1 style="background: '.$this->logLevels[$level].';color: #ffffff;padding: 5px;" class="monolog-output">'.$title.'</h1>';
76 }
83 public function format(array $record)
84 {
85 $output = $this->addTitle($record['level_name'], $record['level']);
86 $output .= '<table cellspacing="1" width="100%" class="monolog-output">';
87
88 $output .= $this->addRow('Message', (string) $record['message']);
89 $output .= $this->addRow('Time', $record['datetime']->format($this->dateFormat));
90 $output .= $this->addRow('Channel', $record['channel']);
91 if ($record['context']) {
92 $embeddedTable = '<table cellspacing="1" width="100%">';
93 foreach ($record['context'] as $key => $value) {
94 $embeddedTable .= $this->addRow($key, $this->convertToString($value));
95 }
96 $embeddedTable .= '</table>';
97 $output .= $this->addRow('Context', $embeddedTable, false);
98 }
99 if ($record['extra']) {
100 $embeddedTable = '<table cellspacing="1" width="100%">';
101 foreach ($record['extra'] as $key => $value) {
102 $embeddedTable .= $this->addRow($key, $this->convertToString($value));
103 }
104 $embeddedTable .= '</table>';
105 $output .= $this->addRow('Extra', $embeddedTable, false);
106 }
107
108 return $output.'</table>';
109 }
110
117 public function formatBatch(array $records)
118 {
119 $message = '';
120 foreach ($records as $record) {
121 $message .= $this->format($record);
122 }
123
124 return $message;
125 }
126
127 protected function convertToString($data)
128 {
129 if (null === $data || is_scalar($data)) {
130 return (string) $data;
131 }
132
133 $data = $this->normalize($data);
134 if (version_compare(PHP_VERSION, '5.4.0', '>=')) {
135 return json_encode($data, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
136 }
137
138 return str_replace('\\/', '/', json_encode($data));
139 }
140}
Formats incoming records into an HTML table.
$logLevels
Translates Monolog log levels to html color priorities.
format(array $record)
Formats a log record.
formatBatch(array $records)
Formats a set of log records.
addTitle($title, $level)
Create a HTML h1 tag.
addRow($th, $td=' ', $escapeTd=true)
Creates an HTML table row.
Normalizes incoming records to remove objects/resources so it's easier to dump to various targets.
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