Skip to content
This repository was archived by the owner on Oct 15, 2025. It is now read-only.

Commit 48bae10

Browse files
committed
refactor(config): Migrate monolog.yaml to PHP
1 parent 4c853eb commit 48bae10

File tree

2 files changed

+67
-62
lines changed

2 files changed

+67
-62
lines changed

config/packages/monolog.php

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
6+
use Symfony\Config\MonologConfig;
7+
8+
return static function (ContainerConfigurator $containerConfigurator, MonologConfig $monologConfig): void {
9+
// Deprecations are logged in the dedicated "deprecation" channel when it exists
10+
$monologConfig->channels(['deprecation']);
11+
12+
if ('dev' === $containerConfigurator->env()) {
13+
$monologConfig->handler('main')
14+
->type('stream')
15+
->path('%kernel.logs_dir%/%kernel.environment%.log')
16+
->level('debug')
17+
->channels()
18+
->elements(['!event']);
19+
$monologConfig->handler('console')
20+
->type('console')
21+
->processPsr3Messages(false)
22+
->channels()
23+
->elements(['!event', '!doctrine', '!console']);
24+
}
25+
26+
if ('test' === $containerConfigurator->env()) {
27+
$monologConfig->handler('main')
28+
->type('fingers_crossed')
29+
->actionLevel('error')
30+
->handler('nested')
31+
->excludedHttpCode(404)
32+
->excludedHttpCode(405)
33+
->channels()
34+
->elements(['!event']);
35+
$monologConfig->handler('nested')
36+
->type('stream')
37+
->path('%kernel.logs_dir%/%kernel.environment%.log')
38+
->level('debug');
39+
}
40+
41+
if ('prod' === $containerConfigurator->env()) {
42+
$monologConfig->handler('main')
43+
->type('fingers_crossed')
44+
->actionLevel('error')
45+
->handler('nested')
46+
->excludedHttpCode(404)
47+
->excludedHttpCode(405)
48+
// How many messages should be saved? Prevent memory leaks
49+
->bufferSize(50);
50+
$monologConfig->handler('nested')
51+
->type('stream')
52+
->path('php://stderr')
53+
->level('debug')
54+
->formatter('monolog.formatter.json');
55+
$monologConfig->handler('console')
56+
->type('console')
57+
->processPsr3Messages(false)
58+
->channels()
59+
->elements(['!event', '!doctrine']);
60+
$monologConfig->handler('deprecation')
61+
->type('stream')
62+
->path('php://stderr')
63+
->formatter('monolog.formatter.json')
64+
->channels()
65+
->elements(['deprecation']);
66+
}
67+
};

config/packages/monolog.yaml

Lines changed: 0 additions & 62 deletions
This file was deleted.

0 commit comments

Comments
 (0)