pastel.codes/config/winston.js

30 lines
731 B
JavaScript
Raw Normal View History

2020-06-22 21:46:41 +01:00
var winston = require('winston');
2020-06-22 22:53:27 +01:00
var appRoot = require('app-root-path');
2020-06-22 21:46:41 +01:00
2020-06-22 22:48:48 +01:00
var logger = new winston.createLogger({
2020-06-22 21:46:41 +01:00
transports: [
2020-06-22 22:48:48 +01:00
new winston.transports.File({
level: 'info',
2020-06-22 22:53:27 +01:00
filename: `${appRoot}/logs/app.log`,
2020-06-22 22:48:48 +01:00
handleExceptions: true,
json: true,
maxsize: 5242880, //5MB
maxFiles: 5,
colorize: false
}),
new winston.transports.Console({
level: 'debug',
handleExceptions: true,
json: false,
colorize: true
})
2020-06-22 21:46:41 +01:00
],
2020-06-22 22:48:48 +01:00
exitOnError: false
2020-06-22 21:46:41 +01:00
});
logger.stream = {
2020-06-22 22:48:48 +01:00
write: function(message, encoding){
2020-06-22 21:46:41 +01:00
logger.info(message);
2020-06-22 22:48:48 +01:00
}
2020-06-22 21:46:41 +01:00
};
2020-06-22 22:48:48 +01:00
module.exports = logger