JsonFormatter::format()   A
last analyzed

Complexity

Conditions 3
Paths 4

Size

Total Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 15
c 0
b 0
f 0
rs 9.7666
cc 3
nc 4
nop 1
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: reallyli
5
 * Date: 18/10/10
6
 * Time: 下午4:46.
7
 */
8
9
namespace Reallyli\LaravelUnicomponent\Components\LogFormatter;
10
11
use Monolog\Formatter\JsonFormatter as BaseJsonFormatter;
12
13
class JsonFormatter extends BaseJsonFormatter implements FormatterInterface
14
{
15
    /**
16
     * Method description:format.
17
     *
18
     * @author reallyli <[email protected]>
19
     * @since 18/10/10
20
     * @param array $record
21
     * @return mixed
22
     * 返回值类型:string,array,object,mixed(多种,不确定的),void(无返回值)
23
     */
24
    public function format(array $record)
25
    {
26
        $newRecord = [
27
            'time' => $record['datetime']->format('Y-m-d H:i:s'),
28
            'level' => $record['level_name'],
29
            'channel' => $record['channel'],
30
            'message' => $record['message'],
31
        ];
32
33
        if (! empty($record['context'])) {
34
            $newRecord = array_merge($newRecord, $record['context']);
35
        }
36
37
        return $this->toJson($this->normalize($newRecord), true).($this->appendNewline ? "\n" : '');
38
    }
39
}
40