I want to log the uncaught exceptions with Winston and exit process. I've configured logger like this
var winston = require('winston');
var logger = new (winston.Logger)({
transports: [
new winston.transports.File({ filename: './all-logs.log', timestamp: true, maxsize: 1000000 })
],
exceptionHandlers: [
new winston.transports.File({ filename: './exceptions.log', timestamp: true, maxsize: 1000000 })
],
exitOnError: true,
});
Then try throw one error, but no exceptions.logs file was created
throw new Exception("Error here ...");
Did I have the right configuration?
I also ran into this problem, and was successful with the following example:
var winston = require('winston');
var logger = new (winston.Logger)({
transports: [
new winston.transports.Console(
{
level: 'debug',
colorize: true,
timestamp: true
}),
new winston.transports.File(
{
level: 'info',
colorize: false,
timestamp: true,
json: true,
filename: '/var/log/mylog.log',
handleExceptions: true
})
]
});
x();
@kenperkins is correct, but this is fixed in HEAD will go out in the next day or two.
if i get uncaughtException application going to exit.
i want to handle uncaughtException without exit appliaction.
@gowthaman-i2i this is the winston based example:
var winston = require('winston');
var logger = new (winston.Logger)({
transports: [
new winston.transports.File({ filename: './all-logs.log', timestamp: true, maxsize: 1000000 })
],
exceptionHandlers: [
new winston.transports.File({ filename: './exceptions.log', timestamp: true, maxsize: 1000000 })
],
exitOnError: false, // <--- set this to false
});
but @3rd-Eden is correct this can be handled in multiple places :+1:
Most helpful comment
@gowthaman-i2i this is the
winstonbased example:but @3rd-Eden is correct this can be handled in multiple places :+1: