53 lines
1.1 KiB
JavaScript
53 lines
1.1 KiB
JavaScript
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
|