2018-02-27 12:16:17 +00:00
|
|
|
'use strict'
|
|
|
|
|
|
|
|
const fs = require('fs')
|
|
|
|
const cluster = require('cluster')
|
|
|
|
|
|
|
|
exports['default'] = {
|
2018-12-17 16:34:32 +00:00
|
|
|
logger: api => {
|
|
|
|
let logger = { transports: [] }
|
2018-02-27 12:16:17 +00:00
|
|
|
|
|
|
|
// console logger
|
|
|
|
if (cluster.isMaster) {
|
|
|
|
logger.transports.push(function (api, winston) {
|
2018-12-17 16:34:32 +00:00
|
|
|
return new winston.transports.Console({
|
2018-02-27 12:16:17 +00:00
|
|
|
colorize: true,
|
|
|
|
level: 'info',
|
2018-12-17 16:34:32 +00:00
|
|
|
timestamp: function () {
|
|
|
|
return api.id + ' @ ' + new Date().toISOString()
|
|
|
|
}
|
2018-02-27 12:16:17 +00:00
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
// file logger
|
|
|
|
logger.transports.push(function (api, winston) {
|
|
|
|
if (api.config.general.paths.log.length === 1) {
|
|
|
|
const logDirectory = api.config.general.paths.log[0]
|
|
|
|
try {
|
|
|
|
fs.mkdirSync(logDirectory)
|
|
|
|
} catch (e) {
|
|
|
|
if (e.code !== 'EEXIST') {
|
2018-12-17 16:34:32 +00:00
|
|
|
throw new Error('Cannot create log directory @ ' + logDirectory)
|
2018-02-27 12:16:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-17 16:34:32 +00:00
|
|
|
return new winston.transports.File({
|
|
|
|
filename:
|
|
|
|
api.config.general.paths.log[0] + '/' + api.pids.title + '.log',
|
2018-02-27 12:16:17 +00:00
|
|
|
level: 'info',
|
2018-12-17 16:34:32 +00:00
|
|
|
timestamp: function () {
|
|
|
|
return api.id + ' @ ' + new Date().toISOString()
|
|
|
|
}
|
2018-02-27 12:16:17 +00:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
// the maximum length of param to log (we will truncate)
|
|
|
|
logger.maxLogStringLength = 100
|
|
|
|
|
|
|
|
// you can optionally set custom log levels
|
|
|
|
// logger.levels = {good: 0, bad: 1};
|
|
|
|
|
|
|
|
// you can optionally set custom log colors
|
|
|
|
// logger.colors = {good: 'blue', bad: 'red'};
|
|
|
|
|
|
|
|
return logger
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
exports.test = {
|
2018-12-17 16:34:32 +00:00
|
|
|
logger: api => {
|
2018-02-27 12:16:17 +00:00
|
|
|
return {
|
|
|
|
transports: null
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|