Forever log and logrotate
Asked Answered
W

2

16

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 ?

Weatherford answered 18/4, 2014 at 10:17 Comment(3)
Are you sure you're using copytruncate?Crumb
copytruncate do the job thank youWeatherford
Awesome. It would be great if you could answer your own question and explain how you were able to solve the problem. This will help other users who run into the same problem :)Crumb
W
21

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  
}
Weatherford answered 8/4, 2015 at 12:16 Comment(3)
My forever logs keep growing forever what can I do? Also the logrotation add up to that, they keep getting bigger and bigger.Venice
Caution! copytruncate can drop log entries. Specifically, the log entries written between the copy and the truncate operations.Gastongastralgia
There is a poblem: when the logrotate logrotates forever is not able to write logs anymore...Erdmann
J
0

i think it's because of living stream between forever and the log file.

forever use file stream to log file. and you renamed this file by logrotate. but stream don't change. so log messages were written in api_output.log-20140418.

if you want to change stream, you should rotate by node.js code, or use pipeline.

Joshua answered 16/12, 2014 at 13:12 Comment(1)
Yes, it was that but copytruncate option avoid the problem !Weatherford

© 2022 - 2024 — McMap. All rights reserved.