From 7a03776bc860bde4cdc82e69ab133a755b66dd2d Mon Sep 17 00:00:00 2001 From: Michael Stokoe Date: Wed, 18 Dec 2019 11:38:06 +0000 Subject: [PATCH 1/4] Updated createEmergencyLogger This allows for an emergency logger channel config item in config/logging.php Use case: Serverless environment or Docker container without persistent storage. If main logger fails, logs may be lost. This will help prevent that by allowing us to specify stderr or stdout as the logger's path. (This will allow us to forward logs onto an ELK stack etc.) --- src/Illuminate/Log/LogManager.php | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/Illuminate/Log/LogManager.php b/src/Illuminate/Log/LogManager.php index 2dff01503a2d..bedba6ceabf7 100644 --- a/src/Illuminate/Log/LogManager.php +++ b/src/Illuminate/Log/LogManager.php @@ -159,13 +159,17 @@ protected function parseTap($tap) /** * Create an emergency log handler to avoid white screens of death. * - * @return \Psr\Log\LoggerInterface + * @return \Illuminate\Log\Logger|\Psr\Log\LoggerInterface */ protected function createEmergencyLogger() { - return new Logger(new Monolog('laravel', $this->prepareHandlers([new StreamHandler( - $this->app->storagePath().'/logs/laravel.log', $this->level(['level' => 'debug']) - )])), $this->app['events']); + $config = $this->configurationFor('emergency'); + + return new Logger( + new Monolog('laravel', $this->prepareHandlers([ + new StreamHandler($config['path'], $this->level(['level' => 'debug'])), + ])), $this->app['events'] + ); } /** From 5ab9fc460ee1750f5cff5a84a368d2fcea144d32 Mon Sep 17 00:00:00 2001 From: Michael Stokoe Date: Wed, 18 Dec 2019 12:37:34 +0000 Subject: [PATCH 2/4] Update LogManager.php --- src/Illuminate/Log/LogManager.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Illuminate/Log/LogManager.php b/src/Illuminate/Log/LogManager.php index bedba6ceabf7..ceef72bce9a5 100644 --- a/src/Illuminate/Log/LogManager.php +++ b/src/Illuminate/Log/LogManager.php @@ -167,7 +167,7 @@ protected function createEmergencyLogger() return new Logger( new Monolog('laravel', $this->prepareHandlers([ - new StreamHandler($config['path'], $this->level(['level' => 'debug'])), + new StreamHandler($config['path'] ?? storage_path('logs/laravel.log'), $this->level(['level' => 'debug'])), ])), $this->app['events'] ); } From 61a320be0ec3d01a3a801e80310624bdc2a44b88 Mon Sep 17 00:00:00 2001 From: Graham Campbell Date: Wed, 18 Dec 2019 13:23:15 +0000 Subject: [PATCH 3/4] Not allowed to use the storage_path helper outside of Foundation --- src/Illuminate/Log/LogManager.php | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/Illuminate/Log/LogManager.php b/src/Illuminate/Log/LogManager.php index ceef72bce9a5..952aa96127e5 100644 --- a/src/Illuminate/Log/LogManager.php +++ b/src/Illuminate/Log/LogManager.php @@ -165,10 +165,14 @@ protected function createEmergencyLogger() { $config = $this->configurationFor('emergency'); + $handler = new StreamHandler( + $config['path'] ?? $this->app->storagePath().'/logs/laravel.log', + $this->level(['level' => 'debug']) + ); + return new Logger( - new Monolog('laravel', $this->prepareHandlers([ - new StreamHandler($config['path'] ?? storage_path('logs/laravel.log'), $this->level(['level' => 'debug'])), - ])), $this->app['events'] + new Monolog('laravel', $this->prepareHandlers([$handler])), + $this->app['events'] ); } From ac580a3ac9365977628740bfaaba3266a059206b Mon Sep 17 00:00:00 2001 From: Graham Campbell Date: Wed, 18 Dec 2019 13:25:15 +0000 Subject: [PATCH 4/4] Revert change to doc --- src/Illuminate/Log/LogManager.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Illuminate/Log/LogManager.php b/src/Illuminate/Log/LogManager.php index 952aa96127e5..1165ac0929ec 100644 --- a/src/Illuminate/Log/LogManager.php +++ b/src/Illuminate/Log/LogManager.php @@ -159,7 +159,7 @@ protected function parseTap($tap) /** * Create an emergency log handler to avoid white screens of death. * - * @return \Illuminate\Log\Logger|\Psr\Log\LoggerInterface + * @return \Psr\Log\LoggerInterface */ protected function createEmergencyLogger() {