|
@@ -128,6 +128,11 @@ class Logger implements LoggerInterface
|
|
|
*/
|
|
*/
|
|
|
protected $processors;
|
|
protected $processors;
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * @var bool
|
|
|
|
|
+ */
|
|
|
|
|
+ protected $microsecondTimestamps = true;
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
* @param string $name The logging channel
|
|
* @param string $name The logging channel
|
|
|
* @param HandlerInterface[] $handlers Optional stack of handlers, the first one in the array is called first, etc.
|
|
* @param HandlerInterface[] $handlers Optional stack of handlers, the first one in the array is called first, etc.
|
|
@@ -239,6 +244,25 @@ class Logger implements LoggerInterface
|
|
|
return $this->processors;
|
|
return $this->processors;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * Control the use of microsecond resolution timestamps in the 'datetime'
|
|
|
|
|
+ * member of new records.
|
|
|
|
|
+ *
|
|
|
|
|
+ * 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.
|
|
|
|
|
+ *
|
|
|
|
|
+ * @param bool $micro True to use microtime() to create timestamps
|
|
|
|
|
+ */
|
|
|
|
|
+ public function useMicrosecondTimestamps($micro)
|
|
|
|
|
+ {
|
|
|
|
|
+ $this->microsecondTimestamps = (bool)$micro;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
* Adds a log record.
|
|
* Adds a log record.
|
|
|
*
|
|
*
|
|
@@ -272,13 +296,20 @@ class Logger implements LoggerInterface
|
|
|
static::$timezone = new \DateTimeZone(date_default_timezone_get() ?: 'UTC');
|
|
static::$timezone = new \DateTimeZone(date_default_timezone_get() ?: 'UTC');
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ if ($this->microsecondTimestamps) {
|
|
|
|
|
+ $ts = \DateTime::createFromFormat('U.u', sprintf('%.6F', microtime(true)), static::$timezone);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ $ts = new \DateTime(null, static::$timezone);
|
|
|
|
|
+ }
|
|
|
|
|
+ $ts->setTimezone(static::$timezone);
|
|
|
|
|
+
|
|
|
$record = array(
|
|
$record = array(
|
|
|
'message' => (string) $message,
|
|
'message' => (string) $message,
|
|
|
'context' => $context,
|
|
'context' => $context,
|
|
|
'level' => $level,
|
|
'level' => $level,
|
|
|
'level_name' => $levelName,
|
|
'level_name' => $levelName,
|
|
|
'channel' => $this->name,
|
|
'channel' => $this->name,
|
|
|
- 'datetime' => \DateTime::createFromFormat('U.u', sprintf('%.6F', microtime(true)), static::$timezone)->setTimezone(static::$timezone),
|
|
|
|
|
|
|
+ 'datetime' => $ts,
|
|
|
'extra' => array(),
|
|
'extra' => array(),
|
|
|
);
|
|
);
|
|
|
|
|
|