2016-05-07 6 views
0

私はすでに私のロガーのセットアップ、通常のエラー/イベントなどの取り扱いに加えて私のアプリのパフォーマンスログを処理するためにウィンストン・logglyセットアップしようとしている:私は、winston loggly出力をタグでグループ化しますか?

var winston = require('winston'); 
require('winston-loggly'); 

winston.setLevels({ error: 0, warn: 1, info: 2, verbose: 3, debug: 4, silly: 5 }); 

winston.addColors({ 
    silly: 'magenta', 
    verbose: 'cyan', 
    debug: 'blue', 
    info: 'green', 
    warn: 'yellow', 
    error: 'red' 
}); 

winston.remove(winston.transports.Console); 
winston.add(winston.transports.Console, { 
    level: 'silly', 
    prettyPrint: true, 
    colorize: true, 
    silent: false, 
    timestamp: true 
}); 



winston.add(winston.transports.Loggly, { 
     token: "MY-TOKEN", 
     subdomain: "MY-SUBDOMAIN", 
     tags: ["Winston-NodeJS"], 
     json:true 
    }); 


module.exports.info = function(message, arg){ 
    winston.log('info',message, arg); 
}; 

module.exports.error = function(message, arg){ 
    winston.log('error', message, arg); 
}; 

module.exports.warn = function(message, arg){ 
    winston.log('warn', message, arg); 
}; 

module.exports.debug = function(message, arg){ 
    winston.log('debug', message, arg); 
}; 

module.exports.winston = winston; 

そして、各ルートのパフォーマンスをキャプチャします「私は私のメインapp.jsでlogglyにパイプすることができたモルガンを使用してきまし:

var theHTTPLog = morgan("dev", { 
    "stream": { 
    write: function(str) { 
     logger.info(str, null); 
    } 
    } 
}); 


app.use(theHTTPLog); 

しかし、これは通常のアプリケーションの出力と同じ汚染モルガン出力を残します。私はそれを分けることができるように、logglyに送られたときにすべてのモーガンの出力を「パフォーマンス」とタグ付けし、それを集計してルートがどのように実行されているかに関する統計を得る方法を見つけ出すことを望みます。ログ時にタグをどのように割り当てることができますか?

答えて

0

タグよりも優れた解決策は、特定の種類のメッセージに対してカスタムログレベルを作成し、それらを新しいレベルでログに記録することです。

関連する問題