How to register "caught" exceptions?

When winston handles caught exceptions, it prints good information about an uncaught exception. How can I do the same for โ€œcaught exceptionsโ€?

if (err) { // winston. log the catched exception } 

I checked the source and seems to be the logException method, but I don't know how to use it.

 var logger = new winston.Logger({ transports: [new winston.transports.Console({handleExceptions: true})] }) var err = new Error('test error.') logger.logException(err.message) //no method 'logException' 
+7
source share
3 answers

You may throw an exception thrown for processing, the error will be caused by winston.Logger. Example:

 process.emit('uncaughtException', err); 
+1
source
 var winston = require('winston'); var err = new Error('test error.'); winston.error(winston.exception.getAllInfo(err)); 
+1
source

logException is a Transport method, not a Logger class. You need the error method:

 var winston = require('winston'); var logger = new winston.Logger({ transports: [new winston.transports.Console({handleExceptions: true})] }) var err = new Error('test error.'); logger.error(err.message); 

https://github.com/flatiron/winston#using-logging-levels

0
source

All Articles