Skip to content

Instantly share code, notes, and snippets.

@jeonghwan-kim
Last active May 2, 2018 09:59
Show Gist options
  • Save jeonghwan-kim/9444091 to your computer and use it in GitHub Desktop.
Save jeonghwan-kim/9444091 to your computer and use it in GitHub Desktop.
usage of winston
// set timezone
process.env.TZ = 'Asia/Seoul';
// winston object
var winston = require('winston');
var logger = new (winston.Logger)({
transports: [
new (winston.transports.File)({
filename: 'error.log',
json: false,
timestamp: function () {
return new Date();
}
}),
new (winston.transports.Console)( {
colorize: true,
timestamp: function () {
return new Date();
}
})
]
});
// uncaughted exceptions
process.on('uncaughtException', function (e) {
logger.error(e.stack);
});
// examples
logger.info('This is info')
logger.warn('This is warn')
logger.error('This is error')
try {
throw new Error('Catched exception was ouccered!');
} catch (e) {
logger.error(e.stack);
}
throw new Error('Uncatched exception was ouccered!');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment