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.
Asked
Active
Viewed 1.4k times
2 Answers
41
On Linux, you can use logrotate
(I don't know if there are similar solutions on Windows or macO)
In /etc/logrotate.d/
create a file (eg. sf2_myapp
) and add this content:
/path/to/your/symfony_app/app/logs/prod.log {
daily
missingok
rotate 14
compress
}
You should look for "logrotate" on Google for more information

Daniel Serodio
- 4,229
- 5
- 37
- 33

loicfavory
- 837
- 6
- 14
-
sharedscripts isn't needed if you're just rotating one file and you're not using any scripts (like a postrotate). – mpeters May 29 '14 at 21:23
-
6and if you want for manually force rotation once you made this config file, run `logrotate --force /etc/logrotate.d/sf2_myapp` – Dimitry K Sep 21 '14 at 19:19
29
There is a logger called rotating_file
.
Here is a sample configuration:
monolog:
handlers:
main:
type: rotating_file
path: %kernel.logs_dir%/%kernel.environment%.log
level: debug

Florent
- 12,310
- 10
- 49
- 58
-
@Seldaek Maybe you could post an answer illustrating it? As the creator of Monolog you know better than me how to achieve that! ;-) – Florent Nov 21 '13 at 16:45
-
8As the creator of Monolog I know that I didn't want to rewrite a tool that's been there forever and works very well, but I am no logrotate pro :) Anyway @loicfavory posted a sample logrotate config below so I'll leave it at that. I just wanted to point out that not all tasks are best done with php. – Seldaek Nov 22 '13 at 07:57
-
This would be even better if it had an option to compress old logs too. :) – Adambean Aug 19 '19 at 09:31