Test Failed
Push — master ( a29797...6ce97f )
by huang
06:37
created

StashFormatter   A

Complexity

Total Complexity 12

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 82.35%

Importance

Changes 0
Metric Value
dl 0
loc 44
rs 10
c 0
b 0
f 0
ccs 28
cts 34
cp 0.8235
wmc 12
lcom 1
cbo 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
D formatV1() 0 36 11
1
<?php
2
/**
3
 * @author    jan huang <[email protected]>
4
 * @copyright 2017
5
 *
6
 * @see      https://www.github.com/janhuang
7
 * @see      https://fastdlabs.com
8
 */
9
10
namespace FastD\Logger\Formatter;
11
12
use Monolog\Formatter\LogstashFormatter;
13
14
/**
15
 * Class StashFormatter.
16
 */
17
class StashFormatter extends LogstashFormatter
18
{
19 37
    public function __construct()
20
    {
21 37
        parent::__construct(app()->getName(), get_local_ip(), null, null, self::V1);
22 37
    }
23
24 16
    public function formatV1(array $record)
25
    {
26 16
        if (empty($record['datetime'])) {
27
            $record['datetime'] = gmdate('c');
28
        }
29
        $message = array(
30 16
            '@timestamp' => $record['datetime'],
31 16
            '@version' => version(),
32 16
            'host' => $this->systemName,
33 16
        );
34 16
        if (isset($record['message'])) {
35 16
            $message['message'] = $record['message'];
36 16
        }
37 16
        if (isset($record['channel'])) {
38 16
            $message['channel'] = $record['channel'];
39 16
        }
40 16
        if (isset($record['level_name'])) {
41 16
            $message['level'] = $record['level_name'];
42 16
        }
43 16
        if (!empty($record['extra'])) {
44
            foreach ($record['extra'] as $key => $val) {
45
                $message[$this->extraPrefix.$key] = $val;
46
            }
47
        }
48 16
        if (!empty($record['context'])) {
49 15
            foreach ($record['context'] as $key => $val) {
50 15
                $message[$this->contextPrefix.$key] = $val;
51 15
            }
52 15
        }
53
54 16
        if (isset($message['trace']) && is_array($message['trace'])) {
55 12
            $message['trace'] = implode(PHP_EOL, $message['trace']);
56 12
        }
57
58 16
        return $message;
59
    }
60
}
61