mirror of
https://github.com/Seldaek/monolog.git
synced 2025-08-08 06:06:40 +02:00
Follow useMicroseconds flag when possible
This commit is contained in:
@@ -33,7 +33,7 @@ class PsrLogMessageProcessor
|
|||||||
*/
|
*/
|
||||||
public function __construct(string $dateFormat = null, bool $removeUsedContextFields = false)
|
public function __construct(string $dateFormat = null, bool $removeUsedContextFields = false)
|
||||||
{
|
{
|
||||||
$this->dateFormat = null === $dateFormat ? static::SIMPLE_DATE : $dateFormat;
|
$this->dateFormat = $dateFormat;
|
||||||
$this->removeUsedContextFields = $removeUsedContextFields;
|
$this->removeUsedContextFields = $removeUsedContextFields;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -57,7 +57,13 @@ class PsrLogMessageProcessor
|
|||||||
if (is_null($val) || is_scalar($val) || (is_object($val) && method_exists($val, "__toString"))) {
|
if (is_null($val) || is_scalar($val) || (is_object($val) && method_exists($val, "__toString"))) {
|
||||||
$replacements[$placeholder] = $val;
|
$replacements[$placeholder] = $val;
|
||||||
} elseif ($val instanceof \DateTimeInterface) {
|
} elseif ($val instanceof \DateTimeInterface) {
|
||||||
$replacements[$placeholder] = $val->format($this->dateFormat);
|
if (!$this->dateFormat && $val instanceof \Monolog\DateTimeImmutable) {
|
||||||
|
// handle monolog dates using __toString if no specific dateFormat was asked for
|
||||||
|
// so that it follows the useMicroseconds flag
|
||||||
|
$replacements[$placeholder] = (string) $val;
|
||||||
|
} else {
|
||||||
|
$replacements[$placeholder] = $val->format($this->dateFormat ?: static::SIMPLE_DATE);
|
||||||
|
}
|
||||||
} elseif (is_object($val)) {
|
} elseif (is_object($val)) {
|
||||||
$replacements[$placeholder] = '[object '.get_class($val).']';
|
$replacements[$placeholder] = '[object '.get_class($val).']';
|
||||||
} elseif (is_array($val)) {
|
} elseif (is_array($val)) {
|
||||||
|
Reference in New Issue
Block a user