ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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 protected $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 protected 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 protected 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 }
77
84 public function format(array $record)
85 {
86 $output = $this->addTitle($record['level_name'], $record['level']);
87 $output .= '<table cellspacing="1" width="100%" class="monolog-output">';
88
89 $output .= $this->addRow('Message', (string) $record['message']);
90 $output .= $this->addRow('Time', $record['datetime']->format($this->dateFormat));
91 $output .= $this->addRow('Channel', $record['channel']);
92 if ($record['context']) {
93 $embeddedTable = '<table cellspacing="1" width="100%">';
94 foreach ($record['context'] as $key => $value) {
95 $embeddedTable .= $this->addRow($key, $this->convertToString($value));
96 }
97 $embeddedTable .= '</table>';
98 $output .= $this->addRow('Context', $embeddedTable, false);
99 }
100 if ($record['extra']) {
101 $embeddedTable = '<table cellspacing="1" width="100%">';
102 foreach ($record['extra'] as $key => $value) {
103 $embeddedTable .= $this->addRow($key, $this->convertToString($value));
104 }
105 $embeddedTable .= '</table>';
106 $output .= $this->addRow('Extra', $embeddedTable, false);
107 }
108
109 return $output.'</table>';
110 }
111
118 public function formatBatch(array $records)
119 {
120 $message = '';
121 foreach ($records as $record) {
122 $message .= $this->format($record);
123 }
124
125 return $message;
126 }
127
128 protected function convertToString($data)
129 {
130 if (null === $data || is_scalar($data)) {
131 return (string) $data;
132 }
133
134 $data = $this->normalize($data);
135 if (version_compare(PHP_VERSION, '5.4.0', '>=')) {
136 return json_encode($data, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
137 }
138
139 return str_replace('\\/', '/', json_encode($data));
140 }
141}
An exception for terminatinating execution or to throw for unit testing.
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
if(!is_dir( $entity_dir)) exit("Fatal Error ([A-Za-z0-9]+)\s+" &#(? foreach( $entity_files as $file) $output
$records
Definition: simple_test.php:22