Skip to content
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

Manually deleting log file looses logs #2

Open
Rcomian opened this issue Mar 4, 2016 · 3 comments
Open

Manually deleting log file looses logs #2

Rcomian opened this issue Mar 4, 2016 · 3 comments
Assignees

Comments

@Rcomian
Copy link
Owner

Rcomian commented Mar 4, 2016

If you are logging to a file and that file gets manually deleted, the logger does not re-create the file and continue logging, instead looses logs from that point.

@Rcomian Rcomian self-assigned this Mar 9, 2016
@tonylukasavage
Copy link

tonylukasavage commented Sep 14, 2017

I'm experiencing the same issue, any motion on this? Could be around this line: https://github.com/Rcomian/bunyan-rotating-file-stream/blob/master/lib/rotatingfilestream.js#L132

It handles the write if there's a stream, but doesn't handle the situation where there's no stream, nor does it do anything other than emit an error when the stream write fails.

@tonylukasavage
Copy link

Researching this shows this isn't a bug. Deleting a file removes the reference link to the file's inode. The stream continues to write to the inode, but isn't accessible via the file system since you deleted the link to it. The best thing to do is send a signal (SIGHUP or SIGUSR1) to the logging process when you move its file away so that it can recreate the log file.

It would be my suggestion to close this one.

@Rcomian
Copy link
Owner Author

Rcomian commented Sep 16, 2017

Sorry I haven't responded earlier.

Yes this isn't really a bug as such, hence why I haven't moved on it. But it is something I saw someone do and be surprised about when using the software.

We could work around it by closing and opening the stream periodically - such as at the end of a batch of writes, this doesn't affect performance too much but does add a large cost to starting a new batch of writes which could itself be the reason that multiple logs get written at the same time.

It's not too difficult, just need to choose a scheme and go with it, but as it stands, keeping the file open is a fairly basic and straightforward way to work - just with this quirk when you delete a file.

Once the rotation happens, you do get logs again, so it's not loosing all logs forever.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants