1

I would like to use Monolog in symfony2 application for logging, but my question is how can I split the file every day instead of appending to the same file?

I would like my log file to be somthing like below:

"%kernel.logs_dir%/%kernel.environment%.%date%.log" Which %date% should be replaced with real date.

I read that logrotate but I don't understand how to use it ?

Emii Khaos
  • 9,983
  • 3
  • 34
  • 57

2 Answers2

3

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

Pi Wi
  • 1,076
  • 1
  • 11
  • 20
2

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

GotBatteries
  • 1,346
  • 1
  • 19
  • 28