Skip to content

Commit a137b04

Browse files
committed
Merge branch '3.x' into 4.x
By Jérôme Tamarelle (1) and Sarim Khan (1) * 3.x: Add service definition for SyslogFormatter Allow unset of excluded_http_codes
2 parents e0cd1da + 26a29b9 commit a137b04

File tree

4 files changed

+46
-0
lines changed

4 files changed

+46
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
* Add `enabled` option to `handlers` configuration
1919
* Add `priority` field to `processor` tag
2020
* Add `mongodb` handler and deprecate `mongo`
21+
* Add `monolog.formatter.syslog` service definition to format RFC5424-compliant messages
2122

2223
## 3.10.0 (2023-11-06)
2324

config/monolog.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
use Monolog\Formatter\LogstashFormatter;
2121
use Monolog\Formatter\NormalizerFormatter;
2222
use Monolog\Formatter\ScalarFormatter;
23+
use Monolog\Formatter\SyslogFormatter;
2324
use Monolog\Formatter\WildfireFormatter;
2425
use Monolog\Logger;
2526
use Psr\Log\LoggerInterface;
@@ -48,6 +49,7 @@
4849
->set('monolog.formatter.html', HtmlFormatter::class)
4950
->set('monolog.formatter.json', JsonFormatter::class)
5051
->set('monolog.formatter.line', LineFormatter::class)
52+
->set('monolog.formatter.syslog', SyslogFormatter::class)
5153
->set('monolog.formatter.loggly', LogglyFormatter::class)
5254
->set('monolog.formatter.normalizer', NormalizerFormatter::class)
5355
->set('monolog.formatter.scalar', ScalarFormatter::class)

src/DependencyInjection/Configuration.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -453,9 +453,15 @@ public function getConfigTreeBuilder(): TreeBuilder
453453
->booleanNode('stop_buffering')->defaultTrue()->end()// fingers_crossed
454454
->scalarNode('passthru_level')->defaultNull()->end() // fingers_crossed
455455
->arrayNode('excluded_http_codes') // fingers_crossed
456+
->info('Only for "fingers_crossed" handler type')
457+
->example([403, 404, [400 => ['^/foo', '^/bar']]])
456458
->canBeUnset()
457459
->beforeNormalization()
458460
->always(function ($values) {
461+
if (false === $values) {
462+
return false;
463+
}
464+
459465
return array_map(function ($value) {
460466
/*
461467
* Allows YAML:

tests/DependencyInjection/ConfigurationTest.php

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,43 @@ public function testProcessStringChannels(string $string, string $expectedString
7373
$this->assertEquals($expectedString, $config['handlers']['foobar']['channels']['elements'][0]);
7474
}
7575

76+
public function testUnsetExcludedHttpCodes()
77+
{
78+
$configs = [
79+
[
80+
'handlers' => [
81+
'main' => [
82+
'type' => 'fingers_crossed',
83+
'action_level' => 'error',
84+
'handler' => 'nested',
85+
'excluded_http_codes' => [404, 405],
86+
'channels' => ['!event'],
87+
],
88+
'nested' => [
89+
'type' => 'stream',
90+
'path' => '%kernel.logs_dir%/%kernel.environment%.log',
91+
'level' => 'debug',
92+
],
93+
],
94+
],
95+
[
96+
'handlers' => [
97+
'main' => [
98+
'type' => 'stream',
99+
'path' => '%kernel.logs_dir%/%kernel.environment%.log',
100+
'level' => 'debug',
101+
'excluded_http_codes' => false,
102+
],
103+
],
104+
],
105+
];
106+
107+
$config = $this->process($configs);
108+
109+
$this->assertArrayNotHasKey('excluded_http_codes', $config['handlers']['main']);
110+
$this->assertIsArray($config['handlers']['main']['channels']);
111+
}
112+
76113
public static function provideGelfPublisher(): array
77114
{
78115
return [

0 commit comments

Comments
 (0)