wikijs-fork/server/modules/logger.js

79 lines
2.0 KiB
JavaScript
Raw Normal View History

2017-03-29 00:19:01 +00:00
'use strict'
/* global wiki */
2017-07-29 04:11:22 +00:00
const cluster = require('cluster')
2017-03-29 00:19:01 +00:00
2017-07-29 04:11:22 +00:00
module.exports = () => {
let winston = require('winston')
2017-03-29 00:19:01 +00:00
2017-04-28 22:46:27 +00:00
// Console
2017-03-29 00:19:01 +00:00
2017-04-28 22:46:27 +00:00
let logger = new (winston.Logger)({
level: (wiki.IS_DEBUG) ? 'debug' : 'info',
2017-04-28 22:46:27 +00:00
transports: [
new (winston.transports.Console)({
level: (wiki.IS_DEBUG) ? 'debug' : 'info',
2017-04-28 22:46:27 +00:00
prettyPrint: true,
colorize: true,
silent: false,
timestamp: true
})
]
})
logger.filters.push((level, msg) => {
2017-07-29 04:11:22 +00:00
let processName = (cluster.isMaster) ? 'MASTER' : `WORKER-${cluster.worker.id}`
2017-04-28 22:46:27 +00:00
return '[' + processName + '] ' + msg
2017-03-29 00:19:01 +00:00
})
// External services
if (wiki.config.externalLogging.bugsnag) {
2017-03-29 00:19:01 +00:00
const bugsnagTransport = require('./winston-transports/bugsnag')
2017-04-28 22:46:27 +00:00
logger.add(bugsnagTransport, {
2017-03-29 00:19:01 +00:00
level: 'warn',
key: wiki.config.externalLogging.bugsnag
2017-03-29 00:19:01 +00:00
})
}
if (wiki.config.externalLogging.loggly) {
2017-03-29 00:19:01 +00:00
require('winston-loggly-bulk')
2017-04-28 22:46:27 +00:00
logger.add(winston.transports.Loggly, {
token: wiki.config.externalLogging.loggly.token,
subdomain: wiki.config.externalLogging.loggly.subdomain,
2017-03-29 00:19:01 +00:00
tags: ['wiki-js'],
level: 'warn',
json: true
})
}
if (wiki.config.externalLogging.papertrail) {
2017-03-29 00:19:01 +00:00
require('winston-papertrail').Papertrail // eslint-disable-line no-unused-expressions
2017-04-28 22:46:27 +00:00
logger.add(winston.transports.Papertrail, {
host: wiki.config.externalLogging.papertrail.host,
port: wiki.config.externalLogging.papertrail.port,
2017-03-29 00:19:01 +00:00
level: 'warn',
program: 'wiki.js'
})
}
if (wiki.config.externalLogging.rollbar) {
2017-03-29 00:19:01 +00:00
const rollbarTransport = require('./winston-transports/rollbar')
2017-04-28 22:46:27 +00:00
logger.add(rollbarTransport, {
2017-03-29 00:19:01 +00:00
level: 'warn',
key: wiki.config.externalLogging.rollbar
2017-03-29 00:19:01 +00:00
})
}
if (wiki.config.externalLogging.sentry) {
2017-03-30 01:49:30 +00:00
const sentryTransport = require('./winston-transports/sentry')
2017-04-28 22:46:27 +00:00
logger.add(sentryTransport, {
2017-03-30 01:49:30 +00:00
level: 'warn',
key: wiki.config.externalLogging.sentry
2017-03-30 01:49:30 +00:00
})
}
2017-04-28 22:46:27 +00:00
return logger
2017-03-29 00:19:01 +00:00
}