作者 竞泽

add:handler

... ... @@ -20,15 +20,18 @@ class ExceptionPush
{
$this->parser = new Parser;
$this->agents = $this->getAgents();
$this->agents = static::getAgents();
}
/**
* @param $options
*
* @return array
*/
protected function getAgents(): array
public static function getAgents($options = null): array
{
$agentOpts = (array) static::config('agents');
$agentOpts = $options ? : (array) static::config('agents');
$agents = [];
... ...
<?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);
}
}
... ...