我在stackoverflow中遇到了类似的问题,但没有看到答案。
我目前在我的制作环境中有dev.log和prod.log,我不明白为什么。我应该只有prod.log。
我的dev.log只包含这个(每2分钟重复一次):
[2017-04-21 17:50:02] event.DEBUG: Notified event "console.command" to listener "Symfony\Component\HttpKernel\EventListener\DebugHandlersListener::configure". [] []
[2017-04-21 17:50:02] doctrine.DEBUG: SELECT e0_.id AS id0, e0_.name AS name1, e0_.progress AS progress2, e0_.path AS path3, e0_.data AS data4, e0_.created_at AS created_at5, e0_.updated_at AS updated_at6, (SELECT COUNT(e1_.id) AS dctrn__1 FROM export e1_ WHERE e1_.progress > 0 AND e1_.progress < 100) AS sclr7, e0_.organization_id AS organization_id8, e0_.owner_id AS owner_id9 FROM export e0_ WHERE e0_.progress = 0 HAVING sclr7 = 0 LIMIT 1 [] []
[2017-04-21 17:50:02] event.DEBUG: Notified event "console.terminate" to listener "Symfony\Bundle\SwiftmailerBundle\EventListener\EmailSenderListener::onTerminate". [] []
这是我的config_dev.yml和config_prod.yml monolog configs:
config_dev:
monolog:
handlers:
main:
type: stream
path: %kernel.logs_dir%/%kernel.environment%.log
level: debug
config_prod:
monolog:
handlers:
main_critical:
type: fingers_crossed
action_level: critical
handler: buffered_critical
buffered_critical:
type: buffer
handler: swift_critical
swift_critical:
type: swift_mailer
from_email: %error_mail_sender%
to_email: %error_mail_recipients%
subject: An error occurred
level: debug
main_error:
type: fingers_crossed
action_level: error
handler: grouped_error
grouped_error:
type: group
members: [streamed]
streamed:
type: stream
path: "%kernel.logs_dir%/%kernel.environment%.log"
level: debug
我注意到日志显示控制台命令正在发生,并且每两分钟运行一次命令的cronjob,但我不知道为什么这会转到dev.log ...
非常感谢你的帮助, 干杯
答案 0 :(得分:2)
默认情况下,Symfony命令在Dev环境中执行,这就是为什么它使用您的dev环境配置将各种日志存储在dev.log文件中的原因。
您需要在Symfony命令中使用--env=prod
标志,以明确指示Symfony在产品环境中运行此命令。
注意:
因此,如果您正在通过cron运行命令,请在命令末尾添加--env=prod
标志。
此答案是对@cerad评论的解释。