1
0
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:
Jordi Boggiano
2016-05-20 21:22:48 +01:00
parent e27225dc40
commit 912d813c73
4 changed files with 65 additions and 8 deletions

View File

@@ -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;
}
}