New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
After logrotate creates new file, new log lines fail to write. #15
Comments
This is because Bristol gets no notification of the change, and cannot update its file descriptor to point to the newly updated file. It's for the same reason that you have to restart syslogd after logrotate rotates its logfiles, as well. There are two solutions to this problem: The most convenient option: The safest but more annoying to implement option: |
Thanks a lot for this information. This is really great. I'll use the first option. |
@TomFrost : Why can't you just use a signal to end and restart the file streams? For example: process.on('SIGUSR2', reloadLogs);
var file;
function reloadLogs () {
file.end();
startLogging();
}
function startLogging()
file = fs.createWriteStream(errFile, { flags : 'a' });
} |
Definitely doable -- I wouldn't go so far as to choose the signal on behalf of the user, but a function call in the Bristol api that could be attached to a signal listener (or folder watcher, for that matter) would work. It's important to note that that wouldn't solve everyone's use case, which is why restarting is so common: Consider, for example, running an app inside of a Docker container that logs to a shared volume (common setup for log aggregation tools via Kubernetes/Mesos/ECS/etc). Sending a signal to such a process would be incredibly cumbersome, and in some cases impossible. But with that said, I'd certainly accept a PR for it, or write it myself if there's enough need! |
@TomFrost : Here's my first thought on how to do it: It just implements a "restart" function on every target. I'm sure there's a better way to do it but I felt limited by the fact that targets export a single function and that function gets bound. I couldn't think off the top of my head of a better way to send a command other than |
Thank you @TomFrost. It is working. |
I suspect that when logrotate creates a new empty file (with logrotate.conf option
create
), the writeable stream is gone.Once the app is restarted, new logs can be written again.
Working around this issue by using logrotate.conf option
nocreate
has the same problem. The file is not re-created by Bristol.I don't see any error messages.
The text was updated successfully, but these errors were encountered: