diff --git a/src/Concerns/ProvidesDefaultConfigurationOptions.php b/src/Concerns/ProvidesDefaultConfigurationOptions.php index 7f9319724..36ebe4101 100644 --- a/src/Concerns/ProvidesDefaultConfigurationOptions.php +++ b/src/Concerns/ProvidesDefaultConfigurationOptions.php @@ -35,6 +35,7 @@ public static function prepareApplicationForNextOperation(): array \Laravel\Octane\Listeners\GiveNewApplicationInstanceToDatabaseSessionHandler::class, \Laravel\Octane\Listeners\GiveNewApplicationInstanceToFilesystemManager::class, \Laravel\Octane\Listeners\GiveNewApplicationInstanceToHttpKernel::class, + \Laravel\Octane\Listeners\GiveNewApplicationInstanceToLogManager::class, \Laravel\Octane\Listeners\GiveNewApplicationInstanceToMailManager::class, \Laravel\Octane\Listeners\GiveNewApplicationInstanceToNotificationChannelManager::class, \Laravel\Octane\Listeners\GiveNewApplicationInstanceToPipelineHub::class, diff --git a/src/Listeners/GiveNewApplicationInstanceToLogManager.php b/src/Listeners/GiveNewApplicationInstanceToLogManager.php new file mode 100644 index 000000000..10a2198c0 --- /dev/null +++ b/src/Listeners/GiveNewApplicationInstanceToLogManager.php @@ -0,0 +1,22 @@ +sandbox->resolved('log')) { + return; + } + + if (method_exists($log = $event->sandbox->make('log'), 'setApplication')) { + $log->setApplication($event->sandbox); + } + } +} diff --git a/src/OctaneServiceProvider.php b/src/OctaneServiceProvider.php index 92cae6aad..206e32768 100644 --- a/src/OctaneServiceProvider.php +++ b/src/OctaneServiceProvider.php @@ -136,6 +136,7 @@ protected function bindListeners() $this->app->singleton(Listeners\GiveNewApplicationInstanceToAuthorizationGate::class); $this->app->singleton(Listeners\GiveNewApplicationInstanceToBroadcastManager::class); $this->app->singleton(Listeners\GiveNewApplicationInstanceToHttpKernel::class); + $this->app->singleton(Listeners\GiveNewApplicationInstanceToLogManager::class); $this->app->singleton(Listeners\GiveNewApplicationInstanceToMailManager::class); $this->app->singleton(Listeners\GiveNewApplicationInstanceToNotificationChannelManager::class); $this->app->singleton(Listeners\GiveNewApplicationInstanceToPipelineHub::class); diff --git a/tests/Listeners/GiveNewApplicationInstanceToLogManagerTest.php b/tests/Listeners/GiveNewApplicationInstanceToLogManagerTest.php new file mode 100644 index 000000000..03afaa254 --- /dev/null +++ b/tests/Listeners/GiveNewApplicationInstanceToLogManagerTest.php @@ -0,0 +1,37 @@ +markTestSkipped('Context is not available in this version of Laravel.'); + } + [$app, $worker, $client] = $this->createOctaneContext([ + Request::create('/', 'GET'), + ]); + $path = $app['config']->get('logging.channels.single.path'); + @unlink($path); + + $this->assertFileDoesNotExist($path); + + $app['router']->middleware('web')->get('/', function () { + Context::add('foo', 'bar'); + Log::info('Hello world'); + }); + + $worker->run(); + + $this->assertStringContainsString('{"foo":"bar"}', file_get_contents($path),); + } +} +