1414use Symfony \Component \DependencyInjection \Compiler \CompilerPassInterface ;
1515use Symfony \Component \DependencyInjection \ContainerBuilder ;
1616use Symfony \Component \DependencyInjection \Reference ;
17- use Symfony \Component \HttpKernel \Log \Logger ;
1817
1918class AddDebugLogProcessorPass implements CompilerPassInterface
2019{
@@ -23,38 +22,22 @@ public function process(ContainerBuilder $container)
2322 if (!$ container ->hasDefinition ('profiler ' )) {
2423 return ;
2524 }
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-
25+ if (!$ container ->hasDefinition ('monolog.logger_prototype ' )) {
3326 return ;
3427 }
35-
36- if (!$ container ->hasDefinition ('logger ' )) {
28+ if (!$ container ->hasDefinition ('debug.log_processor ' )) {
3729 return ;
3830 }
3931
40- $ loggerDefinition = $ container ->getDefinition ('logger ' );
41-
42- if (Logger::class === $ loggerDefinition ->getClass ()) {
43- $ loggerDefinition ->setConfigurator ([__CLASS__ , 'configureHttpKernelLogger ' ]);
44- }
32+ $ definition = $ container ->getDefinition ('monolog.logger_prototype ' );
33+ $ definition ->setConfigurator ([__CLASS__ , 'configureLogger ' ]);
34+ $ definition ->addMethodCall ('pushProcessor ' , [new Reference ('debug.log_processor ' )]);
4535 }
4636
47- public static function configureMonologLogger (mixed $ logger )
37+ public static function configureLogger (mixed $ logger )
4838 {
49- if (\in_array (\ PHP_SAPI , [ ' cli ' , ' phpdbg ' ], true ) && \is_object ($ logger ) && method_exists ( $ logger , ' removeDebugLogger ' )) {
39+ if (\is_object ( $ logger ) && method_exists ($ logger, ' removeDebugLogger ' ) && \in_array (\ PHP_SAPI , [ ' cli ' , ' phpdbg ' ], true )) {
5040 $ logger ->removeDebugLogger ();
5141 }
5242 }
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- }
6043}
0 commit comments