我认为我关闭了调试日志(在config.yml,config_dev,config_test中):
monolog:
handlers:
main:
type: stream
path: "%kernel.logs_dir%/%kernel.environment%.log"
level: debug
channels: [!event]
console:
type: stream
path: "%kernel.logs_dir%/console.log"
level: critical
channels: [!event]
但是当我运行phpunit时它会显示调试日志:
[2016-06-19 16:53:29] event.DEBUG: Notified event "{event}" to listener "{listener}". {"event":"kernel.request","listener":"Symfony\\Component\\HttpKernel\\EventListener\\DebugHandlersListener::configure"} []
[2016-06-19 16:53:29] event.DEBUG: Notified event "{event}" to listener "{listener}". {"event":"kernel.request","listener":"Symfony\\Component\\HttpKernel\\EventListener\\DumpListener::configure"} []
[2016-06-19 16:53:29] event.DEBUG: Notified event "{event}" to listener "{listener}". {"event":"kernel.request","listener":"Symfony\\Bundle\\FrameworkBundle\\EventListener\\TestSessionListener::onKernelRequest"} []
[2016-06-19 16:53:29] event.DEBUG: Notified event "{event}" to listener "{listener}". {"event":"kernel.request","listener":"Symfony\\Bundle\\FrameworkBundle\\EventListener\\SessionListener::onKernelRequest"} []
[2016-06-19 16:53:29] event.DEBUG: Notified event "{event}" to listener "{listener}". {"event":"kernel.request","listener":"Symfony\\Component\\HttpKernel\\EventListener\\FragmentListener::onKernelRequest"} []
[2016-06-19 16:53:29] event.DEBUG: Notified event "{event}" to listener "{listener}". {"event":"kernel.request","listener":"Symfony\\Component\\HttpKernel\\EventListener\\RouterListener::onKernelRequest"} []
[2016-06-19 16:53:29] event.DEBUG: Notified event "{event}" to listener "{listener}". {"event":"kernel.request","listener":"Symfony\\Component\\HttpKernel\\EventListener\\LocaleListener::onKernelRequest"} []
[2016-06-19 16:53:29] event.DEBUG: Notified event "{event}" to listener "{listener}". {"event":"kernel.request","listener":"AppBundle\\EventListener\\LocaleListener::onKernelRequest"} []
如何禁用它?
答案 0 :(得分:4)
如果您尝试这样做:
console:
type: stream
path: "%kernel.logs_dir%/console.log"
level: critical
channels: []
那应该没问题。我也遇到了一些问题,我只是根据自己的需要对其进行了评论。 如果您仍然需要对doctrine进行一些调试,只需将!doctrine放在括号中即可。 如果我找到了你,那就是你需要的。
答案 1 :(得分:1)
测试环境似乎在调试模式下运行,该模式在app_dev.php中的应用程序内核$kernel = new AppKernel('dev', true);
中启用。生产环境也是如此,但有一个例外:第二个参数应该为false,这意味着禁用了调试模式。
要摆脱测试环境中的调试输出,您需要将--no-debug
标志传递给您的命令,例如:
php bin/console some:command --env=test --no-debug
对于PHPUnit,它不起作用。您可能需要覆盖dev
环境的应用程序内核:
来自Kris Wallsmith博客的示例:
class AppKernel extends Kernel
{
// ...
protected function initializeContainer()
{
static $first = true;
if ('test' !== $this->getEnvironment()) {
parent::initializeContainer();
return;
}
$debug = $this->debug;
if (!$first) {
// disable debug mode on all but the first initialization
$this->debug = false;
}
// will not work with --process-isolation
$first = false;
try {
parent::initializeContainer();
} catch (\Exception $e) {
$this->debug = $debug;
throw $e;
}
$this->debug = $debug;
}
}