在Symfony2中使用Monolog进行日志旋转

时间:2022-10-16 14:48:56

I'd like to know if there's any possibility to configure Monolog in Symfony2 to create a new log file every day, for example : 2013-11-21-prod.log.

我想知道是否有可能在Symfony2中配置Monolog以每天创建一个新的日志文件,例如:2013-11-21-prod.log。

2 个解决方案

#1


24  

There is a logger called rotating_file.
Here is a sample configuration:

有一个名为rotating_file的记录器。这是一个示例配置:

monolog:
    handlers:
        main:
            type:  rotating_file
            path:  %kernel.logs_dir%/%kernel.environment%.log
            level: debug

#2


36  

On linux, you can use logrotate (I don't know if exists other solutions on windows or macos)

在linux上,你可以使用logrotate(我不知道在windows或macos上是否存在其他解决方案)

In /etc/logrotate.d/ create a file (eg. sf2_myapp) and add this content :

在/etc/logrotate.d/中创建一个文件(例如sf2_myapp)并添加以下内容:

/path/to/your/symfony_app/app/logs/prod.log {
        daily
        missingok
        rotate 14
        compress
}

You should look for logrotate on Google for more infos

您应该在Google上查找logrotate以获取更多信息

#1


24  

There is a logger called rotating_file.
Here is a sample configuration:

有一个名为rotating_file的记录器。这是一个示例配置:

monolog:
    handlers:
        main:
            type:  rotating_file
            path:  %kernel.logs_dir%/%kernel.environment%.log
            level: debug

#2


36  

On linux, you can use logrotate (I don't know if exists other solutions on windows or macos)

在linux上,你可以使用logrotate(我不知道在windows或macos上是否存在其他解决方案)

In /etc/logrotate.d/ create a file (eg. sf2_myapp) and add this content :

在/etc/logrotate.d/中创建一个文件(例如sf2_myapp)并添加以下内容:

/path/to/your/symfony_app/app/logs/prod.log {
        daily
        missingok
        rotate 14
        compress
}

You should look for logrotate on Google for more infos

您应该在Google上查找logrotate以获取更多信息