作者 竞泽

add:remote debug

<?php
namespace Lackoxygen\ExceptionPush\Channels;
namespace Lackoxygen\ExceptionPush\Handler;
use Illuminate\Support\Arr;
use Lackoxygen\ExceptionPush\Dispatcher;
use Lackoxygen\ExceptionPush\ExceptionPush;
use Monolog\Formatter\FormatterInterface;
use Monolog\Formatter\LineFormatter;
use Monolog\Handler\AbstractSyslogHandler;
use Monolog\Logger;
... ... @@ -20,10 +22,22 @@ use Monolog\Logger;
*/
class MonologHandler extends AbstractSyslogHandler
{
/**
* @var \Closure
*/
protected \Closure $dispatcher;
/**
* @var array
*/
protected array $channels = [];
/**
* @param array $channels
* @param $facility
* @param $level
* @param bool $bubble
*/
public function __construct(
array $channels,
$facility = LOG_USER,
... ... @@ -32,14 +46,30 @@ class MonologHandler extends AbstractSyslogHandler
) {
parent::__construct($facility, $level, $bubble);
$this->dispatcher = (new Dispatcher)->default();
$this->dispatcher = Dispatcher::callback();
$this->channels = $channels;
}
/**
* @param array $record
*
* @return void
*/
protected function write(array $record): void
{
$agents = Arr::only(ExceptionPush::config('agents'), $this->channels);
call_user_func($this->dispatcher, $agents, $record);
$callback = $this->dispatcher;
$callback(ExceptionPush::getAgents($agents), [$record['formatted'] ?? '']);
}
/**
* {@inheritDoc}
*/
protected function getDefaultFormatter(): FormatterInterface
{
return new LineFormatter('%channel%.%level_name%: %message% %context% %extra%');
}
}
... ...
... ... @@ -2,6 +2,11 @@
namespace Lackoxygen\ExceptionPush;
use Lackoxygen\ExceptionPush\Agents\Ding;
use Lackoxygen\ExceptionPush\Agents\Wx;
use Lackoxygen\ExceptionPush\Handler\MonologHandler;
use Monolog\Logger;
if (!function_exists('closure')) {
function closure($closure): ?\Closure
{
... ... @@ -24,3 +29,13 @@ if (!function_exists('closure')) {
return $closure instanceof \Closure ? $closure : null;
}
}
if (!function_exists('notify')) {
function notify($message, $label = 'info')
{
$log = new Logger('notify');
$log->pushHandler(new MonologHandler([Ding::class, Wx::class]));
$log->{$label}($message);
}
}
... ...