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

[fix] catch exceptions for file transport unlinkSync #266

Closed
wants to merge 1 commit into from

Conversation

calvinfo
Copy link
Contributor

@calvinfo calvinfo commented Jun 7, 2013

Using cluster, I sometimes run more than one winston logger on a
single instance. Occasionally they both detect that they should
remove the log file, and one will unlink before the other. This
adds a try...catch to make sure that the unlinkSync call doesn't
throw.

I'd be happy to modify the PR to provide some way of notifying the
developer that the unlink failed. I didn't see a good one off the bat,
ordinarily I'd use something like debug().

Using cluster, I sometimes run more than one winston logger on a
single instance. Occasionally they both detect that they should
remove the log file, and one will unlink before the other. This
adds a try...catch to make sure that the unlinkSync call doesn't
throw.
@diversario
Copy link

I have the same issue. Workaround, I suppose, it to have a separate file for each logger instance, but that gets messy.

@indexzero
Copy link
Member

This looks good. Will go into the next version of winston@0.8.x

@indexzero
Copy link
Member

Cherry-picked. Thanks!

@indexzero indexzero closed this Oct 6, 2014
@shaharke
Copy link

This still happens in winston 0.9.0.

@shaharke
Copy link

Here's the stack trace:

fs.js:765
return binding.unlink(pathModule._makeLong(path));
^
Error: ENOENT, no such file or directory '/var/log/bigpanda/intelligence.log'
at Object.fs.unlinkSync (fs.js:765:18)
at File._getFile (/opt/bigpanda/intelligence/node_modules/bp-api-common/node_modules/winston/lib/winston/transports/file.js:557:12)
at /opt/bigpanda/intelligence/node_modules/bp-api-common/node_modules/winston/lib/winston/transports/file.js:529:31
at Object.oncomplete (fs.js:107:15)

And the relevant lines:
https://github.com/winstonjs/winston/blob/v0.9.0/lib/winston/transports/file.js#L557-L557

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

Successfully merging this pull request may close these issues.

4 participants