Skip to content

Commit 50afb5b

Browse files
timacdonalddriesvints
authored andcommitted
Refreshes log manager container (#910)
* Refreshes log manager container * formatting
1 parent 710e72d commit 50afb5b

File tree

4 files changed

+58
-0
lines changed

4 files changed

+58
-0
lines changed

src/Concerns/ProvidesDefaultConfigurationOptions.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ public static function prepareApplicationForNextOperation(): array
3535
\Laravel\Octane\Listeners\GiveNewApplicationInstanceToDatabaseSessionHandler::class,
3636
\Laravel\Octane\Listeners\GiveNewApplicationInstanceToFilesystemManager::class,
3737
\Laravel\Octane\Listeners\GiveNewApplicationInstanceToHttpKernel::class,
38+
\Laravel\Octane\Listeners\GiveNewApplicationInstanceToLogManager::class,
3839
\Laravel\Octane\Listeners\GiveNewApplicationInstanceToMailManager::class,
3940
\Laravel\Octane\Listeners\GiveNewApplicationInstanceToNotificationChannelManager::class,
4041
\Laravel\Octane\Listeners\GiveNewApplicationInstanceToPipelineHub::class,
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
3+
namespace Laravel\Octane\Listeners;
4+
5+
class GiveNewApplicationInstanceToLogManager
6+
{
7+
/**
8+
* Handle the event.
9+
*
10+
* @param mixed $event
11+
*/
12+
public function handle($event): void
13+
{
14+
if (! $event->sandbox->resolved('log')) {
15+
return;
16+
}
17+
18+
if (method_exists($log = $event->sandbox->make('log'), 'setApplication')) {
19+
$log->setApplication($event->sandbox);
20+
}
21+
}
22+
}

src/OctaneServiceProvider.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ protected function bindListeners()
136136
$this->app->singleton(Listeners\GiveNewApplicationInstanceToAuthorizationGate::class);
137137
$this->app->singleton(Listeners\GiveNewApplicationInstanceToBroadcastManager::class);
138138
$this->app->singleton(Listeners\GiveNewApplicationInstanceToHttpKernel::class);
139+
$this->app->singleton(Listeners\GiveNewApplicationInstanceToLogManager::class);
139140
$this->app->singleton(Listeners\GiveNewApplicationInstanceToMailManager::class);
140141
$this->app->singleton(Listeners\GiveNewApplicationInstanceToNotificationChannelManager::class);
141142
$this->app->singleton(Listeners\GiveNewApplicationInstanceToPipelineHub::class);
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
3+
namespace Laravel\Octane\Tests\Listeners;
4+
5+
use Illuminate\Http\Request;
6+
use Illuminate\Support\Facades\Context;
7+
use Illuminate\Support\Facades\Log;
8+
use Laravel\Octane\Tests\TestCase;
9+
10+
class GiveNewApplicationInstanceToLogManagerTest extends TestCase
11+
{
12+
public function test_context_is_appened_to_logs()
13+
{
14+
if (! class_exists(Context::class)) {
15+
$this->markTestSkipped('Context is not available in this version of Laravel.');
16+
}
17+
[$app, $worker, $client] = $this->createOctaneContext([
18+
Request::create('/', 'GET'),
19+
]);
20+
$path = $app['config']->get('logging.channels.single.path');
21+
@unlink($path);
22+
23+
$this->assertFileDoesNotExist($path);
24+
25+
$app['router']->middleware('web')->get('/', function () {
26+
Context::add('foo', 'bar');
27+
Log::info('Hello world');
28+
});
29+
30+
$worker->run();
31+
32+
$this->assertStringContainsString('{"foo":"bar"}', file_get_contents($path));
33+
}
34+
}

0 commit comments

Comments
 (0)