I'm attempting to setup winston-loggly to handle performance logging in my app in addition to already handling normal errors/events etc. My logger setup:
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;
And then to capture performance of each route, I've been using Morgan which I was able to pipe to loggly in my main app.js:
var theHTTPLog = morgan("dev", {
"stream": {
write: function(str) {
logger.info(str, null);
}
}
});
app.use(theHTTPLog);
However this leaves morgan output polluting the same as normal app output. I'd like to tag all morgan output with "performance" when it's sent to loggly so that I can separate it and hopefully figure out a way to aggregate it to get statistics on how my routes are performing. How can I assign a tag at log time?
A better solution than tags is to create a custom log level for specific types of messages and log them at the new level.