MonologHandler.php
1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
<?php
namespace Lackoxygen\ExceptionPush\Channels;
use Illuminate\Support\Arr;
use Lackoxygen\ExceptionPush\Dispatcher;
use Lackoxygen\ExceptionPush\ExceptionPush;
use Monolog\Handler\AbstractSyslogHandler;
use Monolog\Logger;
/**
* 'papertrail' => [
* 'driver' => 'monolog',
* 'level' => env('LOG_LEVEL', 'debug'),
* 'handler' => SyslogUdpHandler::class,
* 'handler_with' => [
* 'channels' => [Wx::class, Ding::class]
* ],
* ],
*/
class MonologHandler extends AbstractSyslogHandler
{
protected \Closure $dispatcher;
protected array $channels = [];
public function __construct(
array $channels,
$facility = LOG_USER,
$level = Logger::DEBUG,
bool $bubble = true
) {
parent::__construct($facility, $level, $bubble);
$this->dispatcher = (new Dispatcher)->default();
$this->channels = $channels;
}
protected function write(array $record): void
{
$agents = Arr::only(ExceptionPush::config('agents'), $this->channels);
call_user_func($this->dispatcher, $agents, $record);
}
}