mirror of
https://github.com/Seldaek/monolog.git
synced 2025-10-25 02:26:16 +02:00
Switch to DateTimeImmutable everywhere
This commit is contained in:
@@ -37,7 +37,7 @@ class LogglyFormatter extends JsonFormatter
|
||||
*/
|
||||
public function format(array $record)
|
||||
{
|
||||
if (isset($record["datetime"]) && ($record["datetime"] instanceof \DateTime)) {
|
||||
if (isset($record["datetime"]) && ($record["datetime"] instanceof \DateTimeInterface)) {
|
||||
$record["timestamp"] = $record["datetime"]->format("Y-m-d\TH:i:s.uO");
|
||||
unset($record["datetime"]);
|
||||
}
|
||||
|
||||
@@ -85,7 +85,7 @@ class NormalizerFormatter implements FormatterInterface
|
||||
return $normalized;
|
||||
}
|
||||
|
||||
if ($data instanceof \DateTime) {
|
||||
if ($data instanceof \DateTimeInterface) {
|
||||
return $data->format($this->dateFormat);
|
||||
}
|
||||
|
||||
|
||||
@@ -104,7 +104,7 @@ class WildfireFormatter extends NormalizerFormatter
|
||||
|
||||
protected function normalize($data)
|
||||
{
|
||||
if (is_object($data) && !$data instanceof \DateTime) {
|
||||
if (is_object($data) && !$data instanceof \DateTimeInterface) {
|
||||
return $data;
|
||||
}
|
||||
|
||||
|
||||
@@ -33,7 +33,7 @@ class ChromePHPHandler extends AbstractProcessingHandler
|
||||
* Header name
|
||||
*/
|
||||
const HEADER_NAME = 'X-ChromeLogger-Data';
|
||||
|
||||
|
||||
/**
|
||||
* Regular expression to detect supported browsers (matches any Chrome, or Firefox 43+)
|
||||
*/
|
||||
@@ -146,7 +146,7 @@ class ChromePHPHandler extends AbstractProcessingHandler
|
||||
'level' => Logger::WARNING,
|
||||
'level_name' => Logger::getLevelName(Logger::WARNING),
|
||||
'channel' => 'monolog',
|
||||
'datetime' => new \DateTime(),
|
||||
'datetime' => new \DateTimeImmutable(),
|
||||
'extra' => array(),
|
||||
);
|
||||
self::$json['rows'][count(self::$json['rows']) - 1] = $this->getFormatter()->format($record);
|
||||
|
||||
@@ -48,7 +48,7 @@ class RotatingFileHandler extends StreamHandler
|
||||
{
|
||||
$this->filename = $filename;
|
||||
$this->maxFiles = (int) $maxFiles;
|
||||
$this->nextRotation = new \DateTime('tomorrow');
|
||||
$this->nextRotation = new \DateTimeImmutable('tomorrow');
|
||||
$this->filenameFormat = '{filename}-{date}';
|
||||
$this->dateFormat = 'Y-m-d';
|
||||
|
||||
@@ -112,7 +112,7 @@ class RotatingFileHandler extends StreamHandler
|
||||
{
|
||||
// update filename
|
||||
$this->url = $this->getTimedFilename();
|
||||
$this->nextRotation = new \DateTime('tomorrow');
|
||||
$this->nextRotation = new \DateTimeImmutable('tomorrow');
|
||||
|
||||
// skip GC of old logs if files are unlimited
|
||||
if (0 === $this->maxFiles) {
|
||||
|
||||
@@ -316,9 +316,9 @@ class Logger implements LoggerInterface
|
||||
}
|
||||
|
||||
if ($this->microsecondTimestamps) {
|
||||
$ts = \DateTime::createFromFormat('U.u', sprintf('%.6F', microtime(true)), $this->timezone);
|
||||
$ts = \DateTimeImmutable::createFromFormat('U.u', sprintf('%.6F', microtime(true)), $this->timezone);
|
||||
} else {
|
||||
$ts = new \DateTime('', $this->timezone);
|
||||
$ts = new \DateTimeImmutable('', $this->timezone);
|
||||
}
|
||||
$ts->setTimezone($this->timezone);
|
||||
|
||||
|
||||
@@ -31,7 +31,7 @@ class TestCase extends \PHPUnit_Framework_TestCase
|
||||
'level' => $level,
|
||||
'level_name' => Logger::getLevelName($level),
|
||||
'channel' => 'test',
|
||||
'datetime' => \DateTime::createFromFormat('U.u', sprintf('%.6F', microtime(true))),
|
||||
'datetime' => \DateTimeImmutable::createFromFormat('U.u', sprintf('%.6F', microtime(true))),
|
||||
'extra' => array(),
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user