summaryrefslogtreecommitdiffstats
path: root/src/Monolog
diff options
context:
space:
mode:
authorJordi Boggiano <j.boggiano@seld.be>2016-05-26 17:39:41 +0100
committerJordi Boggiano <j.boggiano@seld.be>2016-05-26 18:04:51 +0100
commit76a91c672213a17cb0de82f20e7a28c6f014eacf (patch)
treea44608bb9044b38b41c2945bda0d8025749c0911 /src/Monolog
parent912d813c7345ffe97ddcf1469bd3223fdf27d538 (diff)
downloadmonolog-76a91c672213a17cb0de82f20e7a28c6f014eacf.zip
monolog-76a91c672213a17cb0de82f20e7a28c6f014eacf.tar.gz
monolog-76a91c672213a17cb0de82f20e7a28c6f014eacf.tar.bz2
Set default date format to have a timezone, fixes #196
Diffstat (limited to 'src/Monolog')
-rw-r--r--src/Monolog/DateTimeImmutable.php10
-rw-r--r--src/Monolog/Formatter/NormalizerFormatter.php10
2 files changed, 13 insertions, 7 deletions
diff --git a/src/Monolog/DateTimeImmutable.php b/src/Monolog/DateTimeImmutable.php
index 6187c5a..f1536f4 100644
--- a/src/Monolog/DateTimeImmutable.php
+++ b/src/Monolog/DateTimeImmutable.php
@@ -34,10 +34,7 @@ class DateTimeImmutable extends \DateTimeImmutable implements \JsonSerializable
$this->useMicroseconds = $useMicroseconds;
}
- /**
- * @return string
- */
- public function jsonSerialize()
+ public function jsonSerialize(): string
{
if ($this->useMicroseconds) {
return $this->format('Y-m-d\TH:i:s.uP');
@@ -45,4 +42,9 @@ class DateTimeImmutable extends \DateTimeImmutable implements \JsonSerializable
return $this->format('Y-m-d\TH:i:sP');
}
+
+ public function __toString(): string
+ {
+ return $this->jsonSerialize();
+ }
}
diff --git a/src/Monolog/Formatter/NormalizerFormatter.php b/src/Monolog/Formatter/NormalizerFormatter.php
index 1b2e99c..d73ac65 100644
--- a/src/Monolog/Formatter/NormalizerFormatter.php
+++ b/src/Monolog/Formatter/NormalizerFormatter.php
@@ -12,6 +12,7 @@
namespace Monolog\Formatter;
use Throwable;
+use Monolog\DateTimeImmutable;
/**
* Normalizes incoming records to remove objects/resources so it's easier to dump to various targets
@@ -20,7 +21,7 @@ use Throwable;
*/
class NormalizerFormatter implements FormatterInterface
{
- const SIMPLE_DATE = "Y-m-d H:i:s";
+ const SIMPLE_DATE = "Y-m-d\TH:i:sP";
protected $dateFormat;
@@ -29,7 +30,7 @@ class NormalizerFormatter implements FormatterInterface
*/
public function __construct($dateFormat = null)
{
- $this->dateFormat = $dateFormat ?: static::SIMPLE_DATE;
+ $this->dateFormat = $dateFormat;
if (!function_exists('json_encode')) {
throw new \RuntimeException('PHP\'s json extension is required to use Monolog\'s NormalizerFormatter');
}
@@ -86,7 +87,10 @@ class NormalizerFormatter implements FormatterInterface
}
if ($data instanceof \DateTimeInterface) {
- return $data->format($this->dateFormat);
+ if ($data instanceof DateTimeImmutable) {
+ return (string) $data;
+ }
+ return $data->format($this->dateFormat ?: static::SIMPLE_DATE);
}
if (is_object($data)) {