EloquentHandler::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 2
dl 0
loc 3
ccs 0
cts 3
cp 0
crap 2
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace JustSteveKing\EloquentLogDriver\Handler;
6
7
use Monolog\Logger;
8
use Monolog\Formatter\FormatterInterface;
9
use Monolog\Handler\AbstractProcessingHandler;
10
use JustSteveKing\EloquentLogDriver\Models\DatabaseLog;
11
use JustSteveKing\EloquentLogDriver\Formatter\EloquentFormatter;
12
13
class EloquentHandler extends AbstractProcessingHandler
14
{
15
    public function __construct($level = Logger::DEBUG, bool $bubble = true)
16
    {
17
        parent::__construct($level, $bubble);
18
    }
19
20
    protected function write(array $record): void
21
    {
22
        $log = DatabaseLog::create(
0 ignored issues
show
Unused Code introduced by
The assignment to $log is dead and can be removed.
Loading history...
23
            [
24
            'env'     => $record['channel'],
25
            'message' => $record['message'],
26
            'level'   => $record['level_name'],
27
            'context' => $record['context'],
28
            'extra'   => $record['extra'],
29
            'user_id' => optional(auth()->user())->id ?? null
30
            ]
31
        );
32
    }
33
34
    /**
35
     * {@inheritDoc}
36
     */
37
    protected function getDefaultFormatter(): FormatterInterface
38
    {
39
        return new EloquentFormatter();
40
    }
41
}
42