-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
[Bug]: Filetransport for exceptionHandlers closes after first exception #2311
Comments
Thank you for your reply. Those issues don't seem the same to me. |
Quick work-around I'm currently using (custom const winston = require('winston');
const logger = winston.createLogger({
levels: {exception: 0, error: 1, warn: 2, info: 3, verbose: 4},
format: winston.format.combine(
winston.format.printf(info=>`[${info.level}]: ${info.message}`),
),
transports: [
new winston.transports.File({filename: 'exceptions.log', level: 'exception'}),
new winston.transports.Console(),
],
});
process.on('uncaughtException', (error)=>{
const message = typeof error === 'string' ? error : error.message;
logger.log('exception', `${message}\n${error && error.stack || ' No stack trace'}`);
});
const sleep = (ms)=>new Promise(r=>setTimeout(r, ms));
setTimeout(()=>{
throw 'First exception';
}, 100);
setTimeout(()=>{
throw 'Second exception';
}, 200);
(async ()=>{
await sleep(1000);
console.log('Process end');
})(); Which results in the expected output:
|
If you're able to dive in and see why your exception handler is working but the winston built-in one is not, we'd be more than happy to review a PR... |
I would like to try to investigate this. Looks like will have some time to work on this |
Thank you so much! Like I said, above, happy to review any PR‘s! Bonus points if those come with any kind of new test cases so we can ensure that this functionality remains working in the future :) |
🔎 Search Terms
uncaughtException
The problem
After Winston logged an uncaughtException it seems to close the logfile, which makes the process crash at the next uncaughtException.
The issue might be related to #2219
What version of Winston presents the issue?
v3.9.0
What version of Node are you using?
v18.16.0
If this worked in a previous version of Winston, which was it?
No response
Minimum Working Example
Additional information
Without the second exception present in the code, the output looks (as expected) like this:
But when we include the second exception the process crashes and the output looks like:
With
DEBUG=winston:file
we see the file gets closed after the first exception:The text was updated successfully, but these errors were encountered: