1
0
mirror of https://github.com/Seldaek/monolog.git synced 2025-10-24 18:16:10 +02:00

Fix microseconds support on 7.1, and enable it by default as 7.1 has no perf cost anymore

This commit is contained in:
Jordi Boggiano
2016-11-14 11:53:15 +01:00
parent 9691bde77a
commit 4a43d9b17c
4 changed files with 16 additions and 8 deletions

View File

@@ -23,10 +23,12 @@ class DateTimeImmutable extends \DateTimeImmutable implements \JsonSerializable
public function __construct($useMicroseconds, \DateTimeZone $timezone = null)
{
static $needsMicrosecondsHack = PHP_VERSION_ID < 70100;
$this->useMicroseconds = $useMicroseconds;
$date = 'now';
if ($useMicroseconds) {
if ($needsMicrosecondsHack && $useMicroseconds) {
$timestamp = microtime(true);
// apply offset of the timezone as microtime() is always UTC

View File

@@ -128,7 +128,7 @@ class Logger implements LoggerInterface
/**
* @var bool
*/
protected $microsecondTimestamps = false;
protected $microsecondTimestamps = true;
/**
* @var DateTimeZone
@@ -251,13 +251,17 @@ class Logger implements LoggerInterface
* Control the use of microsecond resolution timestamps in the 'datetime'
* member of new records.
*
* Generating microsecond resolution timestamps by calling
* On PHP7.0, generating microsecond resolution timestamps by calling
* microtime(true), formatting the result via sprintf() and then parsing
* the resulting string via \DateTime::createFromFormat() can incur
* a measurable runtime overhead vs simple usage of DateTime to capture
* a second resolution timestamp in systems which generate a large number
* of log events.
*
* On PHP7.1 however microseconds are always included by the engine, so
* this setting can be left alone unless you really want to suppress
* microseconds in the output.
*
* @param bool $micro True to use microtime() to create timestamps
*/
public function useMicrosecondTimestamps(bool $micro)