Last active
May 2, 2018 09:59
-
-
Save jeonghwan-kim/9444091 to your computer and use it in GitHub Desktop.
usage of winston
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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