ConsoleFormatter::format()   A
last analyzed

Complexity

Conditions 4
Paths 4

Size

Total Lines 17
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 13
CRAP Score 4

Importance

Changes 0
Metric Value
cc 4
eloc 13
nc 4
nop 1
dl 0
loc 17
ccs 13
cts 13
cp 1
crap 4
rs 9.8333
c 0
b 0
f 0
1
<?php
2
3
/*
4
 * This file is part of the Symfony package.
5
 *
6
 * (c) Fabien Potencier <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace CacheTool\Monolog;
13
14
use Monolog\Formatter\LineFormatter;
15
use Monolog\Logger;
16
17
/**
18
 * Formats incoming records for console output by coloring them depending on log level.
19
 *
20
 * @author Tobias Schultze <http://tobion.de>
21
 */
22
class ConsoleFormatter extends LineFormatter
23
{
24
    const SIMPLE_FORMAT = "%start_tag%[%datetime%] %channel%.%level_name%:%end_tag% %message% %context% %extra%\n";
25
26
    /**
27
     * {@inheritdoc}
28
     */
29 20
    public function format(array $record): string
30
    {
31 20
        if ($record['level'] >= Logger::ERROR) {
32 6
            $record['start_tag'] = '<error>';
33 6
            $record['end_tag'] = '</error>';
34 17
        } elseif ($record['level'] >= Logger::NOTICE) {
35 14
            $record['start_tag'] = '<comment>';
36 14
            $record['end_tag'] = '</comment>';
37 5
        } elseif ($record['level'] >= Logger::INFO) {
38 5
            $record['start_tag'] = '<info>';
39 5
            $record['end_tag'] = '</info>';
40
        } else {
41 5
            $record['start_tag'] = '';
42 5
            $record['end_tag'] = '';
43
        }
44
45 20
        return parent::format($record);
46
    }
47
}
48