ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
Monolog\Formatter\HtmlFormatter Class Reference

Formats incoming records into an HTML table. More...

+ Inheritance diagram for Monolog\Formatter\HtmlFormatter:
+ Collaboration diagram for Monolog\Formatter\HtmlFormatter:

Public Member Functions

 __construct ($dateFormat=null)
 
 format (array $record)
 Formats a log record. More...
 
 formatBatch (array $records)
 Formats a set of log records. More...
 
- Public Member Functions inherited from Monolog\Formatter\NormalizerFormatter
 __construct ($dateFormat=null)
 
 format (array $record)
 {Formats a log record.
Parameters
array$recordA record to format
Returns
mixed The formatted record
} More...
 
 formatBatch (array $records)
 {Formats a set of log records.
Parameters
array$recordsA set of records to format
Returns
mixed The formatted set of records
} More...
 

Protected Member Functions

 convertToString ($data)
 
- Protected Member Functions inherited from Monolog\Formatter\NormalizerFormatter
 normalize ($data)
 
 normalizeException (Exception $e)
 
 toJson ($data, $ignoreErrors=false)
 

Private Member Functions

 addRow ($th, $td=' ', $escapeTd=true)
 Creates an HTML table row. More...
 
 addTitle ($title, $level)
 Create a HTML h1 tag. More...
 

Private Attributes

 $logLevels
 Translates Monolog log levels to html color priorities. More...
 

Additional Inherited Members

- Data Fields inherited from Monolog\Formatter\NormalizerFormatter
const SIMPLE_DATE = "Y-m-d H:i:s"
 
- Protected Attributes inherited from Monolog\Formatter\NormalizerFormatter
 $dateFormat
 

Detailed Description

Formats incoming records into an HTML table.

This is especially useful for html email logging

Author
Tiago Brito tlfbr.nosp@m.ito@.nosp@m.gmail.nosp@m..com

Definition at line 22 of file HtmlFormatter.php.

Constructor & Destructor Documentation

◆ __construct()

Monolog\Formatter\HtmlFormatter::__construct (   $dateFormat = null)
Parameters
string$dateFormatThe format of the timestamp: one supported by DateTime::format

Definition at line 41 of file HtmlFormatter.php.

References Monolog\Formatter\NormalizerFormatter\$dateFormat.

42  {
43  parent::__construct($dateFormat);
44  }

Member Function Documentation

◆ addRow()

Monolog\Formatter\HtmlFormatter::addRow (   $th,
  $td = ' ',
  $escapeTd = true 
)
private

Creates an HTML table row.

Parameters
string$thRow header content
string$tdRow standard cell content
bool$escapeTdfalse if td content must not be html escaped
Returns
string

Definition at line 54 of file HtmlFormatter.php.

Referenced by Monolog\Formatter\HtmlFormatter\format().

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  }
+ Here is the caller graph for this function:

◆ addTitle()

Monolog\Formatter\HtmlFormatter::addTitle (   $title,
  $level 
)
private

Create a HTML h1 tag.

Parameters
string$titleText to be in the h1
integer$levelError level
Returns
string

Definition at line 71 of file HtmlFormatter.php.

Referenced by Monolog\Formatter\HtmlFormatter\format().

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  }
+ Here is the caller graph for this function:

◆ convertToString()

Monolog\Formatter\HtmlFormatter::convertToString (   $data)
protected

Definition at line 127 of file HtmlFormatter.php.

References $data, and Monolog\Formatter\NormalizerFormatter\normalize().

Referenced by Monolog\Formatter\HtmlFormatter\format().

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  }
$data
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ format()

Monolog\Formatter\HtmlFormatter::format ( array  $record)

Formats a log record.

Parameters
array$recordA record to format
Returns
mixed The formatted record

Implements Monolog\Formatter\FormatterInterface.

Definition at line 83 of file HtmlFormatter.php.

References Monolog\Formatter\HtmlFormatter\addRow(), Monolog\Formatter\HtmlFormatter\addTitle(), and Monolog\Formatter\HtmlFormatter\convertToString().

Referenced by Monolog\Formatter\HtmlFormatter\formatBatch().

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  }
format(array $record)
Formats a log record.
addRow($th, $td=' ', $escapeTd=true)
Creates an HTML table row.
addTitle($title, $level)
Create a HTML h1 tag.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ formatBatch()

Monolog\Formatter\HtmlFormatter::formatBatch ( array  $records)

Formats a set of log records.

Parameters
array$recordsA set of records to format
Returns
mixed The formatted set of records

Implements Monolog\Formatter\FormatterInterface.

Definition at line 117 of file HtmlFormatter.php.

References Monolog\Formatter\HtmlFormatter\format().

118  {
119  $message = '';
120  foreach ($records as $record) {
121  $message .= $this->format($record);
122  }
123 
124  return $message;
125  }
format(array $record)
Formats a log record.
$records
Definition: simple_test.php:17
+ Here is the call graph for this function:

Field Documentation

◆ $logLevels

Monolog\Formatter\HtmlFormatter::$logLevels
private
Initial value:
= array(
Logger::DEBUG => '#cccccc',
Logger::INFO => '#468847',
Logger::NOTICE => '#3a87ad',
Logger::WARNING => '#c09853',
Logger::ERROR => '#f0ad4e',
Logger::CRITICAL => '#FF7708',
Logger::ALERT => '#C12A19',
Logger::EMERGENCY => '#000000',
)

Translates Monolog log levels to html color priorities.

Definition at line 27 of file HtmlFormatter.php.


The documentation for this class was generated from the following file: