mergeConfigFrom(__DIR__.'/../config/loghandler.php', 'loghandler'); $this->app->singleton(LogForwarder::class, function (Application $app): LogForwarder { $settings = $app['config']->get('loghandler', []); $timeoutSeconds = max(0.0, ((int) ($settings['timeout_ms'] ?? 3000)) / 1000); $client = new Client([ 'timeout' => $timeoutSeconds, 'connect_timeout' => $timeoutSeconds, 'http_errors' => false, ]); return new LogForwarder($app['config'], $client); }); } public function boot(): void { if ($this->app->runningInConsole()) { $this->publishes([ __DIR__.'/../config/loghandler.php' => $this->app->configPath('loghandler.php'), ], 'loghandler-config'); } Log::extend('loghandler', function (Application $app, array $config = []): Logger { $logger = new Logger($config['name'] ?? 'loghandler'); $levelOption = $config['level'] ?? null; try { $level = $levelOption === null ? Level::Debug : Level::fromName(strtoupper((string) $levelOption)); } catch (Throwable) { $level = Level::Debug; } $logger->pushHandler(new LogForwardingHandler( $app->make(LogForwarder::class), $level, ! isset($config['bubble']) || (bool) $config['bubble'], )); return $logger; }); } }