Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to log "catched" exceptions?

When winston handles uncaught exceptions it prints a nice info of the uncaught exception.How can I do the same on "catched exceptions"?

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

I checked the source and there seems to be a logException method but I don't know how I could 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'
like image 609
Jürgen Paul Avatar asked May 07 '13 23:05

Jürgen Paul


People also ask

Where should exceptions be logged?

Unless you are going to change the exception, you should only log at the level where you are going to handle the error and not rethrow it. Otherwise your log just has a bunch of "noise", 3 or more of the same message logged, once at each layer.

How do I view exception logs?

Click System administration > Periodic > Services and Application Integration Framework > Exceptions. On the Overview tab, select an exception record. Click the General tab to view additional details about the exception.

How do I create an exception to a log file?

To log a handled exceptionCreate the method that will generate the exception information. Use a Try...Catch block to catch the exception. Put the code that could generate an exception in the Try block. Uncomment the Dim and MsgBox lines to cause a NullReferenceException exception.

Should you log before throwing exception?

Ideally you should log the stack trace provided by the exception, or throw the exception and log the event further up the stack.


1 Answers

You can emit catched exception back to process, error will by catched by winston.Logger. Example:

process.emit('uncaughtException', err);
like image 89
user3350661 Avatar answered Sep 29 '22 14:09

user3350661