Skip to content

Instantly share code, notes, and snippets.

@melihovv
Created June 18, 2015 14:19
Show Gist options
  • Save melihovv/e9b0af270d862b0ac9b6 to your computer and use it in GitHub Desktop.
Save melihovv/e9b0af270d862b0ac9b6 to your computer and use it in GitHub Desktop.
Winston's wrapper for configurable logging.
var winston = require('winston');
module.exports = function (module) {
return makeLogger(module.filename);
};
function makeLogger(path) {
// File app.js -> log to console and file 'debug.log'.
if (path.match(/app.js$/)) {
var transports = [
new winston.transports.Console({
timestamp: true,
colorize: true,
level: 'info'
}),
new winston.transports.File({
filename: 'debug.log',
level: 'debug'
})
];
return new winston.Logger({transports: transports});
} else {
// Other files -> no logging.
return new winston.Logger({transports: []});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment