mirror of
https://github.com/Seldaek/monolog.git
synced 2025-10-19 23:56:17 +02:00
Support ext-mongodb's UTCDateTime class in MongoDBFormatter
The legacy driver (i.e. ext-mongo) and MongoDate are not supported on PHP 7.
This commit is contained in:
@@ -11,6 +11,8 @@
|
||||
|
||||
namespace Monolog\Formatter;
|
||||
|
||||
use MongoDB\BSON\UTCDateTime;
|
||||
|
||||
/**
|
||||
* Formats a record for use with the MongoDBHandler.
|
||||
*
|
||||
@@ -100,6 +102,13 @@ class MongoDBFormatter implements FormatterInterface
|
||||
|
||||
protected function formatDate(\DateTime $value, $nestingLevel)
|
||||
{
|
||||
return new \MongoDate($value->getTimestamp());
|
||||
$seconds = (int) $value->format('U');
|
||||
$milliseconds = (int) $value->format('u') / 1000;
|
||||
|
||||
if ($seconds < 0) {
|
||||
return new UTCDateTime($seconds * 1000 - $milliseconds);
|
||||
} else {
|
||||
return new UTCDateTime($seconds * 1000 + $milliseconds);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user