From 8ae5837b1b02e23e956a22bec4e51632fea8927e Mon Sep 17 00:00:00 2001 From: Cyril Mazur Date: Sun, 11 Feb 2018 22:41:47 +0800 Subject: [PATCH] [5.6] Fix cache for loggers (#23118) * Cache loggers * Test LogManager caches Logger instances * Use assertSame --- src/Illuminate/Log/LogManager.php | 2 +- tests/Log/LogManagerTest.php | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) create mode 100755 tests/Log/LogManagerTest.php diff --git a/src/Illuminate/Log/LogManager.php b/src/Illuminate/Log/LogManager.php index df506b92a271..b43afbacf435 100644 --- a/src/Illuminate/Log/LogManager.php +++ b/src/Illuminate/Log/LogManager.php @@ -113,7 +113,7 @@ protected function get($name) { try { return $this->channels[$name] ?? with($this->resolve($name), function ($logger) use ($name) { - return $this->tap($name, new Logger($logger, $this->app['events'])); + return $this->channels[$name] = $this->tap($name, new Logger($logger, $this->app['events'])); }); } catch (Throwable $e) { return tap($this->createEmergencyLogger(), function ($logger) use ($e) { diff --git a/tests/Log/LogManagerTest.php b/tests/Log/LogManagerTest.php new file mode 100755 index 000000000000..3c788d92d22b --- /dev/null +++ b/tests/Log/LogManagerTest.php @@ -0,0 +1,19 @@ +app); + + $logger1 = $manager->channel('single')->getLogger(); + $logger2 = $manager->channel('single')->getLogger(); + + $this->assertSame($logger1, $logger2); + } +}