mirror of
https://github.com/Seldaek/monolog.git
synced 2025-10-21 00:26:10 +02:00
Add our own DateTime implementation to provide nicer JSON output, fixes #736
This commit is contained in:
@@ -315,12 +315,7 @@ class Logger implements LoggerInterface
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($this->microsecondTimestamps) {
|
||||
$ts = \DateTimeImmutable::createFromFormat('U.u', sprintf('%.6F', microtime(true)), $this->timezone);
|
||||
} else {
|
||||
$ts = new \DateTimeImmutable('', $this->timezone);
|
||||
}
|
||||
$ts->setTimezone($this->timezone);
|
||||
$ts = $this->createDateTime();
|
||||
|
||||
$record = array(
|
||||
'message' => $message,
|
||||
@@ -560,4 +555,17 @@ class Logger implements LoggerInterface
|
||||
{
|
||||
return $this->timezone;
|
||||
}
|
||||
|
||||
/**
|
||||
* Circumvent DateTimeImmutable::createFromFormat() which always returns the native DateTime instead of the specialized one
|
||||
*
|
||||
* @link https://bugs.php.net/bug.php?id=60302
|
||||
*/
|
||||
private function createDateTime(): DateTimeImmutable
|
||||
{
|
||||
$dateTime = new DateTimeImmutable($this->microsecondTimestamps, $this->timezone);
|
||||
$dateTime->setTimezone($this->timezone);
|
||||
|
||||
return $dateTime;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user