JustSteveKing /
eloquent-log-driver
| 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
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 |