Skip to content

Commit

Permalink
ShipSaaS Logger
Browse files Browse the repository at this point in the history
  • Loading branch information
sethsandaru committed Oct 24, 2023
1 parent 3b1bf60 commit 4f76635
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion src/ShipSaasUniqueRequestLoggerServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
namespace ShipSaasUniqueRequestLogger;

use Illuminate\Foundation\Console\AboutCommand;
use Illuminate\Log\LogManager;
use Illuminate\Support\ServiceProvider;
use Monolog\Logger as Monolog;
use ShipSaasUniqueRequestLogger\Processor\UniqueRequestIdProcessor;

class ShipSaasUniqueRequestLoggerServiceProvider extends ServiceProvider
{
Expand All @@ -13,9 +16,28 @@ public function boot(): void
{
if ($this->app->runningInConsole()) {
AboutCommand::add(
'ShipSaaS: Laravel Unique Request Id Logger',
'ShipSaaS: Logger',
fn () => ['Version' => static::VERSION]
);
}

$this->app->afterResolving(LogManager::class, function (LogManager $manager) {
$manager->extend('shipsaas-logger', function (array $config) {
/** @var LogManager $this */

$handler = $this->channel('stack');

return new Monolog(
'shipsaas-logger',
[
...$handler->getHandlers(),
],
[
...$handler->getProcessors(),
$this->app->make(UniqueRequestIdProcessor::class)
]
);
});
});
}
}

0 comments on commit 4f76635

Please sign in to comment.