Skip to content

Commit ef41d7c

Browse files
committed
fix: allow Logger variable {line} to be used without variable {file}
1 parent c377646 commit ef41d7c

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

system/Log/Logger.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,7 @@ protected function interpolate($message, array $context = [])
341341
$replace['{env}'] = ENVIRONMENT;
342342

343343
// Allow us to log the file/line that we are logging from
344-
if (str_contains($message, '{file}')) {
344+
if (str_contains($message, '{file}') || str_contains($message, '{line}')) {
345345
[$file, $line] = $this->determineFile();
346346

347347
$replace['{file}'] = $file;

tests/system/Log/LoggerTest.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,23 @@ public function testLogInterpolatesFileAndLine(): void
236236
$this->assertGreaterThan(1, strpos($logs[0], $expected));
237237
}
238238

239+
public function testLogInterpolatesLineOnly(): void
240+
{
241+
$config = new LoggerConfig();
242+
243+
$logger = new Logger($config);
244+
245+
$_ENV['foo'] = 'bar';
246+
247+
$logger->log('debug', 'Test message Sample {line}');
248+
$line = __LINE__ - 1;
249+
$expected = "Sample {$line}";
250+
251+
$logs = TestHandler::getLogs();
252+
253+
$this->assertGreaterThan(1, strpos($logs[0], $expected));
254+
}
255+
239256
public function testLogInterpolatesExceptions(): void
240257
{
241258
$config = new LoggerConfig();

0 commit comments

Comments
 (0)