我想在 symfony2 应用程序中使用 Monolog 进行日志记录,但我的问题是如何每天拆分文件而不是附加到同一个文件?
我希望我的日志文件如下所示:
"%kernel.logs_dir%/%kernel.environment%.%date%.log" 其中 %date% 应替换为实际日期。
我读了那个 logrotate 但我不明白如何使用它?
我想在 symfony2 应用程序中使用 Monolog 进行日志记录,但我的问题是如何每天拆分文件而不是附加到同一个文件?
我希望我的日志文件如下所示:
"%kernel.logs_dir%/%kernel.environment%.%date%.log" 其中 %date% 应替换为实际日期。
我读了那个 logrotate 但我不明白如何使用它?
Use multiple handlers
Example:
monolog:
handlers:
main:
type: stream
path: %kernel.logs_dir%/%kernel.environment%.log
level: debug
ex1:
type: stream
path: %kernel.logs_dir%/ex1.log
level: info
ex2:
type: stream
path: %kernel.logs_dir%/ex2.log
level: error
It's explained in the Symfony2 Cookbook http://symfony.com/doc/current/cookbook/logging/monolog.html
And specific for you (channels): http://symfony.com/doc/current/cookbook/logging/channels_handlers.html
This will create a new file for each day. You can also define a max number of files.
monolog:
handlers:
main:
type: rotating_file
path: "%kernel.logs_dir%/%kernel.environment%.log"
level: notice
max_files: 10
It will create a date to the file name automatically, so you don't have to worry about that.
http://symfony.com/doc/current/cookbook/logging/monolog.html