Skip to content

Commit

Permalink
Alow to pass exceptionContexts
Browse files Browse the repository at this point in the history
  • Loading branch information
GDXbsv committed Mar 29, 2023
1 parent c94ce4f commit 4044bdd
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
],
Expand Down
11 changes: 7 additions & 4 deletions src/Laravel/LaravelLoggerCreating.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -28,6 +29,8 @@ public function __invoke(array $config)
$channel = $config['channel'];
/** @var ProcessorInterface[] $processors */
$processors = $config['processors'] ?? [];
/** @var array<class-string<\Throwable>, non-empty-list<ExceptionContext>> $exceptionContexts */
$exceptionContexts = $config['exceptionContexts'] ?? [];
/** @var int $level */
$level = $config['level'] ?? Level::Debug;
/** @var string $stream */
Expand All @@ -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);

Expand Down

0 comments on commit 4044bdd

Please sign in to comment.