Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Log rotating with Monolog in Symfony2

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.

like image 795
mneute Avatar asked Nov 21 '13 16:11

mneute


People also ask

What does rotating a log file mean?

In information technology, log rotation is an automated process used in system administration in which log files are compressed, moved (archived), renamed or deleted once they are too old or too big (there can be other metrics that can apply here).

How often logs should be rotated?

Each file should be rotated weekly. The log rotation job runs nightly, though, so this can be changed to daily for a specific log file if desired. The three commands that specify how often rotation should take place are daily, weekly and monthly. Keep four sets of log files.

How Monolog works?

In Monolog, there are a lot of formatters that can be used. You can find some built-in formatters here. You can also customize the format of the logs that are written in files, emails, databases, and other handlers. is the most common way to use a handler with a value to be directly put into the log device.

Where to find Symfony logs?

By default, log entries are written to the var/log/dev. log file when you're in the dev environment.


1 Answers

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

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 infos

like image 178
loicfavory Avatar answered Sep 21 '22 17:09

loicfavory