ILIAS  release_5-2 Revision v5.2.25-18-g3f80b82851
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...
 
 detectAndCleanUtf8 (&$data)
 Detect invalid UTF-8 string characters and convert to valid UTF-8. More...
 

Protected Member Functions

 addRow ($th, $td=' ', $escapeTd=true)
 Creates an HTML table row. More...
 
 addTitle ($title, $level)
 Create a HTML h1 tag. More...
 
 convertToString ($data)
 
- Protected Member Functions inherited from Monolog\Formatter\NormalizerFormatter
 normalize ($data)
 
 normalizeException ($e)
 
 toJson ($data, $ignoreErrors=false)
 Return the JSON representation of a value. More...
 

Protected Attributes

 $logLevels
 Translates Monolog log levels to html color priorities. More...
 
- Protected Attributes inherited from Monolog\Formatter\NormalizerFormatter
 $dateFormat
 

Additional Inherited Members

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

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 
)
protected

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 
)
protected

Create a HTML h1 tag.

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

Definition at line 71 of file HtmlFormatter.php.

References $title.

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 128 of file HtmlFormatter.php.

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

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

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  }
+ 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 84 of file HtmlFormatter.php.

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

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

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  }
format(array $record)
Formats a log record.
if(!is_dir( $entity_dir)) exit("Fatal Error ([A-Za-z0-9]+)\+" &#(? foreach( $entity_files as $file) $output
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 118 of file HtmlFormatter.php.

References Monolog\Formatter\HtmlFormatter\format().

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

Field Documentation

◆ $logLevels

Monolog\Formatter\HtmlFormatter::$logLevels
protected
Initial value:
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: