I use forever to launch my nodeJs server and I choose the log file :
forever -l /home/api/log/api_output.log start server.js
I use logrotate to move logfile every day (like advise here : NodeJS/Forever archive logs), after one day my directory is like this :
-rw-r--r-- 1 root root 0 avril 18 12:00 api_output.log
-rw-r--r-- 1 root root 95492 avril 18 12:01 api_output.log-20140418
So, rotation is working, but the logs messages are now written in api_output.log-20140418, instead of api_output.log
Maybe somebody can help me ?
copytruncate : Truncate the original log file in place after creating a copy, instead of moving the old log file and optionally creating a new one. It can be used when some program cannot be told to close its logfile and thus might continue writing (appending) to the previous log file forever.
logrotate is designed to ease administration of systems that generate large numbers of log files. It allows automatic rotation, compression, removal, and mailing of log files. Each log file may be handled daily, weekly, monthly, or when it grows too large. Normally, logrotate is run as a daily cron job.
The command /usr/bin/chattr -a is run to remove the append-only attribute from /var/log/messages. The endscript command marks the end of the prerotate portion of this script. The next line, postrotate, specifies the following commands are to be run on /var/log/messages after the file has been rotated by logrotate.
Note that usually logrotate is configured to be run by cron daily. You have to change this configuration and run logrotate hourly to be able to really rotate logs hourly. As pointed out by yellow1pl the solution is to copy the file /etc/cron. daily/logrotate into the /etc/cron.
I forgot copytruncate option in my config file, now it's working :
/etc/logrotate.d/api :
/home/api/log/api_output.log {
#size 50k
daily
dateext
missingok
rotate 7
compress
delaycompress
notifempty
#create 644 root
copytruncate
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With