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

logger error event handler not working #511

Closed
prateeksultania opened this issue Dec 12, 2014 · 4 comments
Closed

logger error event handler not working #511

prateeksultania opened this issue Dec 12, 2014 · 4 comments

Comments

@prateeksultania
Copy link

Below is the piece of code I tried to run:-

require('events').EventEmitter
var winston = require('winston');
var fileLogger = new (winston.Logger)({
    transports: [
        new (winston.transports.File)({
            filename: './log/test.log',
            level: 'info',
            timestamp : true,
            json : true
        })
    ]
});
fileLogger.on('error', function (err) {
   console.log(err);
});
fileLogger.info("test log");

Even though I have handled the error event of the logger the code is still throwing an error:

events.js:72
        throw er; // Unhandled 'error' event
Error: ENOENT, open 'log/test.log'
@indexzero
Copy link
Member

This should not happen, but if it is happening it is a bug. What version of winston are you using?

@prateeksultania
Copy link
Author

I am using:-
winston version 0.8.1
node version 0.10.30
ubuntu: 12.04

callbacknull pushed a commit to Silverlink/winston that referenced this issue Mar 16, 2015
Error handling for the `fs.stat` call in daily-rotate & file transports
was setup to only emit errors that weren't ENOENT errors. For ENOENT errors
it calls createAndFlush(0) and then does nothing to handle the error. Logic
was changed to always emit errors and call createAndFlush(0) if the error
is an ENOENT error.

fixes winstonjs#511
callbacknull pushed a commit to Silverlink/winston that referenced this issue Mar 16, 2015
Error handling for the `fs.stat` call in daily-rotate & file transports
was setup to only emit errors that weren't ENOENT errors. For ENOENT errors
it calls createAndFlush(0) and then does nothing to handle the error. Logic
was changed to always emit errors and call createAndFlush(0) if the error
is an ENOENT error.

fixes winstonjs#511
callbacknull pushed a commit to Silverlink/winston that referenced this issue Mar 16, 2015
In this commit file & daily-rotate-file add an 'error' event listener on
their stream so that we can emit those errors from the transport.

fixes winstonjs#511
callbacknull pushed a commit to Silverlink/winston that referenced this issue Mar 16, 2015
In this commit file & daily-rotate-file add an 'error' event listener on
their stream so that we can emit those errors from the transport.

fixes winstonjs#511
@prateeksultania
Copy link
Author

Any idea when will this commit get pulled in trunk?

@pieroadvice
Copy link

I have the same error, hasn't it been fixed yet?

const execution = new winston.Logger({
transports: [
new winston.transports.File({
name: 'execution',
filename: path.join(__dirname, '../../logs/', 'execution.log')
})
]
});
execution.on('error', function (err) {
console.log(err);
});

events.js:160
throw er; // Unhandled 'error' event
^

Error: ENOENT: no such file or directory, open '/Library/WebServer/Documents/apis/desarrollo/chase/logs/execution.log'

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

Successfully merging a pull request may close this issue.

3 participants