2017-03-29 00:19:01 +00:00
|
|
|
'use strict'
|
|
|
|
|
2017-07-23 03:56:46 +00:00
|
|
|
/* 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)({
|
2017-07-23 03:56:46 +00:00
|
|
|
level: (wiki.IS_DEBUG) ? 'debug' : 'info',
|
2017-04-28 22:46:27 +00:00
|
|
|
transports: [
|
|
|
|
new (winston.transports.Console)({
|
2017-07-23 03:56:46 +00:00
|
|
|
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
|
|
|
|
|
2017-07-23 03:56:46 +00:00
|
|
|
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',
|
2017-07-23 03:56:46 +00:00
|
|
|
key: wiki.config.externalLogging.bugsnag
|
2017-03-29 00:19:01 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2017-07-23 03:56:46 +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, {
|
2017-07-23 03:56:46 +00:00
|
|
|
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
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2017-07-23 03:56:46 +00:00
|
|
|
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, {
|
2017-07-23 03:56:46 +00:00
|
|
|
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'
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2017-07-23 03:56:46 +00:00
|
|
|
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',
|
2017-07-23 03:56:46 +00:00
|
|
|
key: wiki.config.externalLogging.rollbar
|
2017-03-29 00:19:01 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2017-07-23 03:56:46 +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',
|
2017-07-23 03:56:46 +00:00
|
|
|
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
|
|
|
}
|