Why does Symfony still log to a dev.log file, even when I didn't define it in a loghandler?

风格不统一 提交于 2019-12-04 08:43:16

REMOVE monolog.handlers.mainfrom config_dev.yml.

It usally contains path: "%kernel.logs_dir%/%kernel.environment%.log"

config _dev.yml (default)

monolog:
    handlers:
        main:   # <- remove this handler
            type:   stream
            path:   "%kernel.logs_dir%/%kernel.environment%.log" #<- logs/dev.log
            level:  debug

Remove the main handler from this config file.

If anyone comes across this and is still interested in why this happens, the debug handler is injected in the \Symfony\Bundle\MonologBundle\DependencyInjection\Compiler\DebugHandlerPass::process() method...

class DebugHandlerPass implements CompilerPassInterface
{
    // ...

    public function process(ContainerBuilder $container)
    {
        if (!$container->hasDefinition('profiler')) {
            return;
        }

        if (!$container->getParameter('kernel.debug')) {
            return;
        }

        $debugHandler = new Definition('%monolog.handler.debug.class%', array(Logger::DEBUG, true));
        $container->setDefinition('monolog.handler.debug', $debugHandler);

        foreach ($this->channelPass->getChannels() as $channel) {
            $container
                ->getDefinition($channel === 'app' ? 'monolog.logger' : 'monolog.logger.'.$channel)
                ->addMethodCall('pushHandler', array(new Reference('monolog.handler.debug')));
        }
    }
}

As you can see, this pushes a new handler on to every registered channel, thus overriding any other handlers that might already have been added.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!