2013-05-07 13 views
7

Gdy winston obsługuje niezatłoczone wyjątki, wypisuje ładną informację o nieprzechwyconym wyjątku. W jaki sposób mogę zrobić to samo w "wyjątkach wychwyconych"?Jak rejestrować wyjątki "catched"?

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

sprawdziłem źródło i wydaje się być logException method ale nie wiem, jak mogę go używać.

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' 

Odpowiedz

0

logException to metoda Transport, nie klasy Logger. Co trzeba to error metoda:

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

1

Można emitować catched wyjątek z powrotem do procesu, błąd będzie być przechwycony przez winston.Logger. Przykład:

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

Może to ze starej wersji Winston, ale nie ma takiego API. https://github.com/winstonjs/winston – Seth

Powiązane problemy