1414use Symfony \Component \DependencyInjection \Compiler \CompilerPassInterface ;
1515use Symfony \Component \DependencyInjection \ContainerBuilder ;
1616use Symfony \Component \DependencyInjection \Reference ;
17+ use Symfony \Component \HttpKernel \Log \Logger ;
1718
1819class AddDebugLogProcessorPass implements CompilerPassInterface
1920{
@@ -22,22 +23,38 @@ public function process(ContainerBuilder $container)
2223 if (!$ container ->hasDefinition ('profiler ' )) {
2324 return ;
2425 }
25- if (!$ container ->hasDefinition ('monolog.logger_prototype ' )) {
26+
27+ if ($ container ->hasDefinition ('monolog.logger_prototype ' ) && $ container ->hasDefinition ('debug.log_processor ' )) {
28+ $ container ->getDefinition ('monolog.logger_prototype ' )
29+ ->setConfigurator ([__CLASS__ , 'configureMonologLogger ' ])
30+ ->addMethodCall ('pushProcessor ' , [new Reference ('debug.log_processor ' )])
31+ ;
32+
2633 return ;
2734 }
28- if (!$ container ->hasDefinition ('debug.log_processor ' )) {
35+
36+ if (!$ container ->hasDefinition ('logger ' )) {
2937 return ;
3038 }
3139
32- $ definition = $ container ->getDefinition ('monolog.logger_prototype ' );
33- $ definition ->setConfigurator ([__CLASS__ , 'configureLogger ' ]);
34- $ definition ->addMethodCall ('pushProcessor ' , [new Reference ('debug.log_processor ' )]);
40+ $ loggerDefinition = $ container ->getDefinition ('logger ' );
41+
42+ if (Logger::class === $ loggerDefinition ->getClass ()) {
43+ $ loggerDefinition ->setConfigurator ([__CLASS__ , 'configureHttpKernelLogger ' ]);
44+ }
3545 }
3646
37- public static function configureLogger (mixed $ logger )
47+ public static function configureMonologLogger (mixed $ logger )
3848 {
39- if (\is_object ( $ logger ) && method_exists ( $ logger , ' removeDebugLogger ' ) && \ in_array (\PHP_SAPI , ['cli ' , 'phpdbg ' ], true )) {
49+ if (\in_array (\PHP_SAPI , ['cli ' , 'phpdbg ' ], true ) && \is_object ( $ logger ) && method_exists ( $ logger , ' removeDebugLogger ' )) {
4050 $ logger ->removeDebugLogger ();
4151 }
4252 }
53+
54+ public static function configureHttpKernelLogger (Logger $ logger )
55+ {
56+ if (!\in_array (\PHP_SAPI , ['cli ' , 'phpdbg ' ], true ) && method_exists ($ logger , 'enableDebug ' )) {
57+ $ logger ->enableDebug ();
58+ }
59+ }
4360}
0 commit comments