I have Node.js application which is running under Linux system and uses log4js logging library. Log files are daily rolled by Linux rolling system. The question is the following: somebody know how force the log4js to recreate and use original log file when it’s renamed somehow? Note, Log4js continue writes log into renamed file (seems, stream descriptor is kept). Please note also that I don’t want to use log4js DaylyRollingFileAppender because my log folder contains log files generated by various languages (Java, Python, JavaScript, Bash…).
Advertisement
Answer
I assume that you use logrotate
.
You can try using ‘reload’ directive in logrotate config file. (see for details: http://www.linuxcommand.org/man_pages/logrotate8.html)
It seems like that log3js can handle SIGHUP. (Issue: https://github.com/nomiddlename/log4js-node/issues/343, Pull request: https://github.com/nomiddlename/log4js-node/pull/403)
Secondary solution is configure it to use ‘copytruncate’ directive, but it has trade-offs: https://serverfault.com/questions/688658/rsyslog-with-logrotate-reload-rsyslog-vs-copytruncate