sifangpay/app/Logging/JsonFormatter.php

26 lines
776 B
PHP
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
namespace App\Logging;
use Monolog\Formatter\JsonFormatter as BaseJsonFormatter;
class JsonFormatter extends BaseJsonFormatter
{
public function format(array $record): string
{
// 这个就是最终要记录的数组最后转成Json并记录进日志
$newRecord = [
'time' => $record['datetime']->format('Y-m-d H:i:s'),
'msg' => $record['message'],
];
if (!empty($record['context'])) {
$newRecord = array_merge($newRecord, $record['context']);
}
//$json = 'aaa,bbb,ccc'; // 这是最终返回的记录串,可以按自己的需求改
$json = $this->toJson($this->normalize($newRecord), true) . ($this->appendNewline ? "\n" : '');
return $json;
}
}