diff options
Diffstat (limited to 'src/Monolog/Processor/PsrLogMessageProcessor.php')
-rw-r--r-- | src/Monolog/Processor/PsrLogMessageProcessor.php | 20 |
1 files changed, 17 insertions, 3 deletions
diff --git a/src/Monolog/Processor/PsrLogMessageProcessor.php b/src/Monolog/Processor/PsrLogMessageProcessor.php index c2686ce..8078403 100644 --- a/src/Monolog/Processor/PsrLogMessageProcessor.php +++ b/src/Monolog/Processor/PsrLogMessageProcessor.php @@ -1,4 +1,4 @@ -<?php +<?php declare(strict_types=1); /* * This file is part of the Monolog package. @@ -20,20 +20,34 @@ namespace Monolog\Processor; */ class PsrLogMessageProcessor { + const SIMPLE_DATE = "Y-m-d\TH:i:sP"; + + private $dateFormat; + + /** + * @param string $dateFormat The format of the timestamp: one supported by DateTime::format + */ + public function __construct(string $dateFormat = null) + { + $this->dateFormat = null === $dateFormat ? static::SIMPLE_DATE : $dateFormat; + } + /** * @param array $record * @return array */ - public function __invoke(array $record) + public function __invoke(array $record): array { if (false === strpos($record['message'], '{')) { return $record; } - $replacements = array(); + $replacements = []; foreach ($record['context'] as $key => $val) { if (is_null($val) || is_scalar($val) || (is_object($val) && method_exists($val, "__toString"))) { $replacements['{'.$key.'}'] = $val; + } elseif ($val instanceof \DateTimeInterface) { + $replacements['{'.$key.'}'] = $val->format($this->dateFormat); } elseif (is_object($val)) { $replacements['{'.$key.'}'] = '[object '.get_class($val).']'; } else { |