1
0
mirror of https://github.com/Seldaek/monolog.git synced 2025-08-11 23:54:04 +02:00

Added possibility to set max length for level name in LineFormatter

Closes #1850
This commit is contained in:
Philipp Müller
2023-10-26 20:33:53 +02:00
committed by Jordi Boggiano
parent 70f6ca05b9
commit 1feb860c33
2 changed files with 52 additions and 0 deletions

View File

@@ -276,6 +276,40 @@ class LineFormatterTest extends TestCase
$this->assertMatchesRegularExpression('/foo\nbar/', $message);
}
/**
* @dataProvider providerMaxLevelNameLength
*/
public function testMaxLevelNameLength(?int $maxLength, Level $logLevel, string $expectedLevelName): void
{
$formatter = new LineFormatter(maxLevelNameLength: $maxLength);
$message = $formatter->format($this->getRecord(message: "foo\nbar", level: $logLevel));
$this->assertStringContainsString("test.$expectedLevelName:", $message);
}
public static function providerMaxLevelNameLength(): array
{
return [
'info_no_max_length' => [
'max_length' => null,
'level' => Level::Info,
'expected_level_name' => 'INFO',
],
'error_max_length_3' => [
'max_length' => 3,
'level' => Level::Error,
'expected_level_name' => 'ERR',
],
'debug_max_length_2' => [
'max_length' => 2,
'level' => Level::Debug,
'expected_level_name' => 'DE',
],
];
}
}
class TestFoo