Completed
Pull Request — master (#40)
by
unknown
01:24
created

MonologHandler::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 2
1
<?php namespace Understand\UnderstandLaravel5\Handlers;
2
3
use Monolog\Handler\AbstractHandler;
4
use Monolog\Logger;
5
use Laravel\Lumen\Application;
6
7
class MonologHandler extends AbstractHandler
8
{
9
    /**
10
     * Mapping between numeric constant and string
11
     *
12
     * @var array
13
     */
14
    protected $levelMap = [
15
        Logger::DEBUG     => 'debug',
16
        Logger::INFO      => 'info',
17
        Logger::NOTICE    => 'notice',
18
        Logger::WARNING   => 'warning',
19
        Logger::ERROR     => 'error',
20
        Logger::CRITICAL  => 'critical',
21
        Logger::ALERT     => 'alert',
22
        Logger::EMERGENCY => 'emergency',
23
    ];
24
25
    /**
26
     * @param string|int $level  The minimum logging level at which this handler will be triggered
27
     * @param bool       $bubble Whether the messages that are handled can bubble up the stack or not
28
     */
29
    public function __construct($level = Logger::DEBUG, $bubble = true)
30
    {
31
        parent::__construct($level, $bubble);
32
    }
33
34
    /**
35
     * Handle the logging of the record.
36
     *
37
     * @param array $record
38
     * @return bool|void
39
     */
40
    public function handle(array $record)
41
    {
42
        $record['level'] = $this->levelMap[$record['level']];
43
44
        // raise event so the record is captured by the ServiceProvider
45
        app('events')->fire('illuminate.log', [$record]);
46
    }
47
}