Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[5.8] Fix stack channel's bug #27726

Merged
merged 3 commits into from Mar 1, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/Illuminate/Log/LogManager.php
Expand Up @@ -335,6 +335,8 @@ protected function createMonologDriver(array $config)
$config['handler_with'] ?? []
);

$with['level'] = $this->level($config);

return new Monolog($this->parseChannel($config), [$this->prepareHandler(
$this->app->make($config['handler'], $with), $config
)]);
Expand Down
47 changes: 46 additions & 1 deletion tests/Log/LogManagerTest.php
Expand Up @@ -27,16 +27,61 @@ public function testLogManagerCachesLoggerInstances()
$this->assertSame($logger1, $logger2);
}

public function testStackChannel()
{
$config = $this->app['config'];

$config->set('logging.channels.stack', [
'driver' => 'stack',
'channels' => ['stderr', 'stdout'],
]);

$config->set('logging.channels.stderr', [
'driver' => 'monolog',
'handler' => StreamHandler::class,
'level' => 'notice',
'with' => [
'stream' => 'php://stderr',
'bubble' => false,
],
]);

$config->set('logging.channels.stdout', [
'driver' => 'monolog',
'handler' => StreamHandler::class,
'level' => 'info',
'with' => [
'stream' => 'php://stdout',
'bubble' => true,
],
]);

$manager = new LogManager($this->app);

// create logger with handler specified from configuration
$logger = $manager->channel('stack');
$handlers = $logger->getLogger()->getHandlers();

$this->assertInstanceOf(Logger::class, $logger);
$this->assertCount(2, $handlers);
$this->assertInstanceOf(StreamHandler::class, $handlers[0]);
$this->assertInstanceOf(StreamHandler::class, $handlers[1]);
$this->assertEquals(Monolog::NOTICE, $handlers[0]->getLevel());
$this->assertEquals(Monolog::INFO, $handlers[1]->getLevel());
$this->assertFalse($handlers[0]->getBubble());
$this->assertTrue($handlers[1]->getBubble());
}

public function testLogManagerCreatesConfiguredMonologHandler()
{
$config = $this->app['config'];
$config->set('logging.channels.nonbubblingstream', [
'driver' => 'monolog',
'name' => 'foobar',
'handler' => StreamHandler::class,
'level' => 'notice',
'with' => [
'stream' => 'php://stderr',
'level' => Monolog::NOTICE,
'bubble' => false,
],
]);
Expand Down