Skip to content

Commit e197b3c

Browse files
authored
fix(log): fix driver resolving not accounting log level (#1343)
1 parent d28e896 commit e197b3c

File tree

2 files changed

+25
-3
lines changed

2 files changed

+25
-3
lines changed

packages/log/src/GenericLogger.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,14 +91,16 @@ private function writeLog(MonologLogLevel $level, string $message, array $contex
9191

9292
private function resolveDriver(LogChannel $channel, MonologLogLevel $level): Monolog
9393
{
94-
if (! isset($this->drivers[spl_object_id($channel)])) {
95-
$this->drivers[spl_object_id($channel)] = new Monolog(
94+
$key = spl_object_id($channel) . $level->value;
95+
96+
if (! isset($this->drivers[$key])) {
97+
$this->drivers[$key] = new Monolog(
9698
name: $this->logConfig->prefix,
9799
handlers: $channel->getHandlers($level),
98100
processors: $channel->getProcessors(),
99101
);
100102
}
101103

102-
return $this->drivers[spl_object_id($channel)];
104+
return $this->drivers[$key];
103105
}
104106
}

tests/Integration/Log/GenericLoggerTest.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,26 @@ public function test_message_logged_emitted(LogLevel $level, string $_expected):
148148
$logger->log($level, 'This is a log message of level: ' . $level->value, context: ['foo' => 'bar']);
149149
}
150150

151+
public function test_different_log_levels_works(): void
152+
{
153+
$filePath = __DIR__ . '/logs/tempest.log';
154+
$config = new LogConfig(
155+
prefix: 'tempest',
156+
channels: [
157+
new AppendLogChannel($filePath),
158+
],
159+
);
160+
161+
$logger = new GenericLogger($config, $this->container->get(EventBus::class));
162+
$logger->critical('critical');
163+
$logger->debug('debug');
164+
165+
$this->assertFileExists($filePath);
166+
$content = file_get_contents($filePath);
167+
$this->assertStringContainsString('critical', $content);
168+
$this->assertStringContainsString('debug', $content);
169+
}
170+
151171
public static function tempestLevelProvider(): array
152172
{
153173
return array_map(fn (LogLevel $level) => [$level, strtoupper($level->value)], LogLevel::cases());

0 commit comments

Comments
 (0)