From 4044bdd5bfb601978b1e67af12469c230f63f814 Mon Sep 17 00:00:00 2001 From: "sergei.baikin" Date: Wed, 29 Mar 2023 09:54:18 +0200 Subject: [PATCH] Alow to pass exceptionContexts --- README.md | 4 ++++ src/Laravel/LaravelLoggerCreating.php | 11 +++++++---- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index a6a7612..27f5721 100644 --- a/README.md +++ b/README.md @@ -72,6 +72,10 @@ add in `config/logging.php` in `channels` section: 'app_name' => 'ServiceName', 'channel' => 'security', 'processors' => [new Monolog\Processor\ProcessorInterface()], //OPTIONAL + 'exceptionContexts' => [ //OPTIONAL + RequestException::class => [new GuzzleRequestExceptionContext()], + AwsException::class => [new AwsExceptionContext()], + ], //OPTIONAL 'level' => Monolog\Logger::INFO, //OPTIONAL 'stream_to' => 'php://stderr', //OPTIONAL ], diff --git a/src/Laravel/LaravelLoggerCreating.php b/src/Laravel/LaravelLoggerCreating.php index 14810bc..3859686 100644 --- a/src/Laravel/LaravelLoggerCreating.php +++ b/src/Laravel/LaravelLoggerCreating.php @@ -6,6 +6,7 @@ use Aws\Exception\AwsException; use Gotphoto\Logging\ExceptionContext\AwsExceptionContext; +use Gotphoto\Logging\ExceptionContext\ExceptionContext; use Gotphoto\Logging\ExceptionContext\GuzzleRequestExceptionContext; use Gotphoto\Logging\Formatter; use Gotphoto\Logging\NewrelicProcessor; @@ -28,6 +29,8 @@ public function __invoke(array $config) $channel = $config['channel']; /** @var ProcessorInterface[] $processors */ $processors = $config['processors'] ?? []; + /** @var array, non-empty-list> $exceptionContexts */ + $exceptionContexts = $config['exceptionContexts'] ?? []; /** @var int $level */ $level = $config['level'] ?? Level::Debug; /** @var string $stream */ @@ -44,12 +47,12 @@ public function __invoke(array $config) $streamHandler = new StreamHandler($stream, $level); $handler = $streamHandler; - $env = App::environment(); + $env = App::environment(); $handler->setFormatter( - new Formatter($appName, (is_string($env) ? $env : "undefined"), [ + new Formatter($appName, (is_string($env) ? $env : "undefined"), array_merge($exceptionContexts, [ RequestException::class => [new GuzzleRequestExceptionContext()], - AwsException::class => [new AwsExceptionContext()], - ]) + AwsException::class => [new AwsExceptionContext()], + ])) ); $log->pushHandler($handler);