kulmapaikka-ircbot/logger.js

53 lines
1.1 KiB
JavaScript
Raw Normal View History

2019-11-20 20:28:11 +02:00
const fs = require('fs')
const path = require('path')
const winston = require('winston')
const logDirectory = path.join(__dirname, '/log/')
// ensure log directory exists
if (!fs.existsSync(logDirectory)) {
fs.mkdirSync(logDirectory)
}
let logger = winston.createLogger({
level: process.env.NODE_ENV !== 'production' ? 'error' : 'debug',
transports: [
new winston.transports.File({
level: 'info',
filename: path.join(logDirectory, '/ircbot.log'),
handleExceptions: true,
json: true,
maxsize: 5242880,
maxFiles: 5,
colorize: false,
timestamp: true
}),
new winston.transports.Console({
level: 'debug',
handleExceptions: true,
json: false,
colorize: true,
timestamp: true
})
],
exceptionHandlers: [
new winston.transports.Console({
json: false,
timestamp: true
}),
new winston.transports.File({
filename: logDirectory + '/exceptions.log',
json: false
})
],
exitOnError: false
})
logger.stream = {
write: function (message, encoding) {
logger.info(message)
}
}
module.exports = logger