diff --git a/src/Monolog/Formatter/HtmlFormatter.php b/src/Monolog/Formatter/HtmlFormatter.php index f07c8715..54778a27 100644 --- a/src/Monolog/Formatter/HtmlFormatter.php +++ b/src/Monolog/Formatter/HtmlFormatter.php @@ -46,14 +46,17 @@ class HtmlFormatter extends NormalizerFormatter /** * Creates an HTML table row * - * @param string $th Row header content - * @param string $td Row standard cell content + * @param string $th Row header content + * @param string $td Row standard cell content + * @param bool $escapeTd false if td content must not be html escaped * @return string */ - private function addRow($th, $td = ' ') + private function addRow($th, $td = ' ', $escapeTd = true) { $th = htmlspecialchars($th, ENT_NOQUOTES, 'UTF-8'); - $td = '
'.htmlspecialchars($td, ENT_NOQUOTES, 'UTF-8').'
'; + if ($escapeTd) { + $td = '
'.htmlspecialchars($td, ENT_NOQUOTES, 'UTF-8').'
'; + } return "\n$th:\n".$td."\n"; } @@ -86,10 +89,20 @@ class HtmlFormatter extends NormalizerFormatter $output .= $this->addRow('Time', $record['datetime']->format('Y-m-d\TH:i:s.uO')); $output .= $this->addRow('Channel', $record['channel']); if ($record['context']) { - $output .= $this->addRow('Context', $this->convertToString($record['context'])); + $embeddedTable = ''; + foreach ($record['context'] as $key => $value) { + $embeddedTable .= $this->addRow($key, $this->convertToString($value)); + } + $embeddedTable .= '
'; + $output .= $this->addRow('Context', $embeddedTable, false); } if ($record['extra']) { - $output .= $this->addRow('Extra', $this->convertToString($record['extra'])); + $embeddedTable = ''; + foreach ($record['extra'] as $key => $value) { + $embeddedTable .= $this->addRow($key, $this->convertToString($value)); + } + $embeddedTable .= '
'; + $output .= $this->addRow('Extra', $embeddedTable, false); } return $output.'';