summaryrefslogtreecommitdiffstats
path: root/src/Monolog/Formatter/HtmlFormatter.php
diff options
context:
space:
mode:
Diffstat (limited to 'src/Monolog/Formatter/HtmlFormatter.php')
-rw-r--r--src/Monolog/Formatter/HtmlFormatter.php26
1 files changed, 12 insertions, 14 deletions
diff --git a/src/Monolog/Formatter/HtmlFormatter.php b/src/Monolog/Formatter/HtmlFormatter.php
index 3eec95f..a343b06 100644
--- a/src/Monolog/Formatter/HtmlFormatter.php
+++ b/src/Monolog/Formatter/HtmlFormatter.php
@@ -1,4 +1,5 @@
-<?php
+<?php declare(strict_types=1);
+
/*
* This file is part of the Monolog package.
*
@@ -24,7 +25,7 @@ class HtmlFormatter extends NormalizerFormatter
/**
* Translates Monolog log levels to html color priorities.
*/
- protected $logLevels = array(
+ protected $logLevels = [
Logger::DEBUG => '#cccccc',
Logger::INFO => '#468847',
Logger::NOTICE => '#3a87ad',
@@ -33,12 +34,12 @@ class HtmlFormatter extends NormalizerFormatter
Logger::CRITICAL => '#FF7708',
Logger::ALERT => '#C12A19',
Logger::EMERGENCY => '#000000',
- );
+ ];
/**
* @param string $dateFormat The format of the timestamp: one supported by DateTime::format
*/
- public function __construct($dateFormat = null)
+ public function __construct(string $dateFormat = null)
{
parent::__construct($dateFormat);
}
@@ -51,7 +52,7 @@ class HtmlFormatter extends NormalizerFormatter
* @param bool $escapeTd false if td content must not be html escaped
* @return string
*/
- protected function addRow($th, $td = ' ', $escapeTd = true)
+ protected function addRow(string $th, string $td = ' ', bool $escapeTd = true): string
{
$th = htmlspecialchars($th, ENT_NOQUOTES, 'UTF-8');
if ($escapeTd) {
@@ -68,7 +69,7 @@ class HtmlFormatter extends NormalizerFormatter
* @param int $level Error level
* @return string
*/
- protected function addTitle($title, $level)
+ protected function addTitle(string $title, int $level)
{
$title = htmlspecialchars($title, ENT_NOQUOTES, 'UTF-8');
@@ -81,13 +82,13 @@ class HtmlFormatter extends NormalizerFormatter
* @param array $record A record to format
* @return mixed The formatted record
*/
- public function format(array $record)
+ public function format(array $record): string
{
$output = $this->addTitle($record['level_name'], $record['level']);
$output .= '<table cellspacing="1" width="100%" class="monolog-output">';
$output .= $this->addRow('Message', (string) $record['message']);
- $output .= $this->addRow('Time', $record['datetime']->format($this->dateFormat));
+ $output .= $this->addRow('Time', $this->formatDate($record['datetime']));
$output .= $this->addRow('Channel', $record['channel']);
if ($record['context']) {
$embeddedTable = '<table cellspacing="1" width="100%">';
@@ -115,7 +116,7 @@ class HtmlFormatter extends NormalizerFormatter
* @param array $records A set of records to format
* @return mixed The formatted set of records
*/
- public function formatBatch(array $records)
+ public function formatBatch(array $records): string
{
$message = '';
foreach ($records as $record) {
@@ -125,17 +126,14 @@ class HtmlFormatter extends NormalizerFormatter
return $message;
}
- protected function convertToString($data)
+ protected function convertToString($data): string
{
if (null === $data || is_scalar($data)) {
return (string) $data;
}
$data = $this->normalize($data);
- if (version_compare(PHP_VERSION, '5.4.0', '>=')) {
- return json_encode($data, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
- }
- return str_replace('\\/', '/', json_encode($data));
+ return json_encode($data, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
}
}