How do I suffix nginx logs with date
Modify the logrotate configuration file for Nginx - /etc/logrotate.d/nginx
to include dateext
and dateformat
.
/var/log/nginx/*.log { <...> dateext dateformat .%Y-%m-%d.log <...> prerotate <...> rm -f /var/log/nginx/access.`date +\\%Y-%m-d`.log rm -f /var/log/nginx/error.`date +\\%Y-%m-d`.log <...> endscript postrotate <...> ln -s /var/log/nginx/access.log /var/log/nginx/access.`date +\\%Y-%m-d`.log ln -s /var/log/nginx/error.log /var/log/nginx/error.`date +\\%Y-%m-d`.log <...> endscript}
Example: access.2015-04-08.log
Read more on logrotate and its configuration directive by executing man logrotate
in your linux.