|
@@ -20,6 +20,18 @@ namespace Monolog\Processor;
|
|
|
*/
|
|
*/
|
|
|
class PsrLogMessageProcessor
|
|
class PsrLogMessageProcessor
|
|
|
{
|
|
{
|
|
|
|
|
+ const SIMPLE_DATE = "Y-m-d\TH:i:sP";
|
|
|
|
|
+
|
|
|
|
|
+ private $dateFormat;
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * @param string $dateFormat The format of the timestamp: one supported by DateTime::format
|
|
|
|
|
+ */
|
|
|
|
|
+ public function __construct(string $dateFormat = null)
|
|
|
|
|
+ {
|
|
|
|
|
+ $this->dateFormat = null === $dateFormat ? static::SIMPLE_DATE : $dateFormat;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
* @param array $record
|
|
* @param array $record
|
|
|
* @return array
|
|
* @return array
|
|
@@ -34,6 +46,8 @@ class PsrLogMessageProcessor
|
|
|
foreach ($record['context'] as $key => $val) {
|
|
foreach ($record['context'] as $key => $val) {
|
|
|
if (is_null($val) || is_scalar($val) || (is_object($val) && method_exists($val, "__toString"))) {
|
|
if (is_null($val) || is_scalar($val) || (is_object($val) && method_exists($val, "__toString"))) {
|
|
|
$replacements['{'.$key.'}'] = $val;
|
|
$replacements['{'.$key.'}'] = $val;
|
|
|
|
|
+ } elseif ($val instanceof \DateTimeInterface) {
|
|
|
|
|
+ $replacements['{'.$key.'}'] = $val->format($this->dateFormat);
|
|
|
} elseif (is_object($val)) {
|
|
} elseif (is_object($val)) {
|
|
|
$replacements['{'.$key.'}'] = '[object '.get_class($val).']';
|
|
$replacements['{'.$key.'}'] = '[object '.get_class($val).']';
|
|
|
} else {
|
|
} else {
|