Completed
Push — 1.x ( 8c31f4...5f4811 )
by Samuel
7s
created

ConsoleFormatter::format()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 18
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 18
rs 9.2
nc 4
cc 4
eloc 14
nop 1
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
    public function format(array $record)
30
    {
31
        if ($record['level'] >= Logger::ERROR) {
32
            $record['start_tag'] = '<error>';
33
            $record['end_tag'] = '</error>';
34
        } elseif ($record['level'] >= Logger::NOTICE) {
35
            $record['start_tag'] = '<comment>';
36
            $record['end_tag'] = '</comment>';
37
        } elseif ($record['level'] >= Logger::INFO) {
38
            $record['start_tag'] = '<info>';
39
            $record['end_tag'] = '</info>';
40
        } else {
41
            $record['start_tag'] = '';
42
            $record['end_tag'] = '';
43
        }
44
45
        return parent::format($record);
46
    }
47
}
48