Skip to content

Commit

Permalink
[5.6] Fix cache for loggers (#23118)
Browse files Browse the repository at this point in the history
* Cache loggers

* Test LogManager caches Logger instances

* Use assertSame
  • Loading branch information
CyrilMazur authored and taylorotwell committed Feb 11, 2018
1 parent 38284c8 commit 8ae5837
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Illuminate/Log/LogManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
19 changes: 19 additions & 0 deletions tests/Log/LogManagerTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

namespace Illuminate\Tests\Log;

use Illuminate\Log\LogManager;
use Orchestra\Testbench\TestCase;

class LogManagerTest extends TestCase
{
public function testLogManagerCachesLoggerInstances()
{
$manager = new LogManager($this->app);

$logger1 = $manager->channel('single')->getLogger();
$logger2 = $manager->channel('single')->getLogger();

$this->assertSame($logger1, $logger2);
}
}

0 comments on commit 8ae5837

Please sign in to comment.