Doesn't log anything to file transport with handleExceptions: true and exitOnError: true (default value).
What do you expect to happen instead?
Error is logged and then the process exits.
Other information
// Create winston logger for writing to the env log
const logger = winston.createLogger({
level: 'debug',
exitOnError: true,
transports: [
new winston.transports.File({
handleExceptions: true,
filename: `${__dirname}/logs/dev.log`,
format: winston.format.combine(
winston.format.timestamp({ format: 'YYYY-MM-DD HH:mm:ss' }),
winston.format.printf(info => `[${info.timestamp}] ${info.level}: ${info.message}`)
)
})
]
});
logger.debug('throwing...');
throw new Error('foo');
If I set exitOnError: false , logging works again (but this is not what I need):
[2018-06-16 19:36:53] debug: throwing...
[2018-06-16 19:36:53] error: uncaughtException: foo
Error: foo
at Object.<anonymous> (C:\Progetti\gremo\angular-fullstack\dist\server\app.js:40:7)
at Module._compile (module.js:652:30)
at Object.Module._extensions..js (module.js:663:10)
at Module.load (module.js:565:32)
at tryModuleLoad (module.js:505:12)
at Function.Module._load (module.js:497:3)
at Function.Module.runMain (module.js:693:10)
at startup (bootstrap_node.js:191:16)
at bootstrap_node.js:612:3
This seems like a duplicate of #1289 which has a pending PR #1355 that would hopefully fix your problem as well. (Waiting for some discussion with @indexzero before merging that in.) Thanks for bringing this up!
Please tell us about your environment:
winston
version?winston@2
winston@3
node -v
outputs: v8.11.2What is the problem?
Doesn't log anything to file transport with
handleExceptions: true
andexitOnError: true
(default value).What do you expect to happen instead?
Error is logged and then the process exits.
Other information
If I set
exitOnError: false
, logging works again (but this is not what I need):