feat: modular logging + setup wizard
This commit is contained in:
		| @@ -31,11 +31,9 @@ module.exports = { | ||||
|  | ||||
|     // Load authentication strategies | ||||
|  | ||||
|     wiki.config.auth.strategies.local = {} | ||||
|  | ||||
|     _.forOwn(wiki.config.auth.strategies, (strategyConfig, strategyKey) => { | ||||
|     _.forOwn(_.omitBy(wiki.config.auth.strategies, s => s.enabled === false), (strategyConfig, strategyKey) => { | ||||
|       strategyConfig.callbackURL = `${wiki.config.site.host}${wiki.config.site.path}/login/${strategyKey}/callback` | ||||
|       let strategy = require(`../authentication/${strategyKey}`) | ||||
|       let strategy = require(`../extensions/authentication/${strategyKey}`) | ||||
|       strategy.init(passport, strategyConfig) | ||||
|       fs.readFile(path.join(wiki.ROOTPATH, `assets/svg/auth-icon-${strategyKey}.svg`), 'utf8').then(iconData => { | ||||
|         strategy.icon = iconData | ||||
| @@ -47,7 +45,7 @@ module.exports = { | ||||
|         } | ||||
|       }) | ||||
|       this.strategies[strategy.key] = strategy | ||||
|       wiki.logger.info(`Authentication Provider ${strategyKey}: OK`) | ||||
|       wiki.logger.info(`Authentication Provider ${strategyKey}: [ OK ]`) | ||||
|     }) | ||||
|  | ||||
|     // Create Guest account for first-time | ||||
|   | ||||
| @@ -80,7 +80,7 @@ module.exports = { | ||||
|     // Attempt to connect and authenticate to DB | ||||
|  | ||||
|     self.inst.authenticate().then(() => { | ||||
|       wiki.logger.info('Database (PostgreSQL) connection: OK') | ||||
|       wiki.logger.info('Database (PostgreSQL) connection: [ OK ]') | ||||
|     }).catch(err => { | ||||
|       wiki.logger.error('Failed to connect to PostgreSQL instance.') | ||||
|       wiki.logger.error(err) | ||||
|   | ||||
| @@ -115,7 +115,7 @@ module.exports = { | ||||
|       wiki.logger.error(err) | ||||
|     } | ||||
|  | ||||
|     wiki.logger.info('Disk Data Paths: OK') | ||||
|     wiki.logger.info('Disk Data Paths: [ OK ]') | ||||
|   }, | ||||
|  | ||||
|   /** | ||||
|   | ||||
| @@ -88,8 +88,8 @@ module.exports = { | ||||
|         self._repo.exists = false | ||||
|       }) | ||||
|     }).then(() => { | ||||
|       if (wiki.config.git === false) { | ||||
|         wiki.logger.warn('Remote Git syncing is disabled. Not recommended!') | ||||
|       if (wiki.config.git.enabled === false) { | ||||
|         wiki.logger.warn('Git Remote Sync: [ DISABLED ]') | ||||
|         return Promise.resolve(true) | ||||
|       } | ||||
|  | ||||
| @@ -129,7 +129,7 @@ module.exports = { | ||||
|       wiki.logger.error('Git remote error!') | ||||
|       throw err | ||||
|     }).then(() => { | ||||
|       wiki.logger.info('Git Repository: OK') | ||||
|       wiki.logger.info('Git Repository: [ OK ]') | ||||
|       return true | ||||
|     }) | ||||
|   }, | ||||
|   | ||||
| @@ -37,11 +37,11 @@ module.exports = { | ||||
|    */ | ||||
|   bootMaster() { | ||||
|     this.preBootMaster().then(sequenceResults => { | ||||
|       if (_.every(sequenceResults, rs => rs === true)) { | ||||
|       if (_.every(sequenceResults, rs => rs === true) && wiki.config.configMode !== 'setup') { | ||||
|         this.postBootMaster() | ||||
|       } else { | ||||
|         wiki.logger.info('Starting configuration manager...') | ||||
|         require('../configure')() | ||||
|         require('../setup')() | ||||
|       } | ||||
|       return true | ||||
|     }).catch(err => { | ||||
| @@ -52,13 +52,15 @@ module.exports = { | ||||
|   /** | ||||
|    * Post-Master Boot Sequence | ||||
|    */ | ||||
|   postBootMaster() { | ||||
|     require('../master')().then(() => { | ||||
|       _.times(this.numWorker, this.spawnWorker) | ||||
|   async postBootMaster() { | ||||
|     await require('../master')() | ||||
|  | ||||
|       wiki.queue.uplClearTemp.add({}, { | ||||
|         repeat: { cron: '*/15 * * * *' } | ||||
|       }) | ||||
|     _.times(this.numWorkers, () => { | ||||
|       this.spawnWorker() | ||||
|     }) | ||||
|  | ||||
|     wiki.queue.uplClearTemp.add({}, { | ||||
|       repeat: { cron: '*/15 * * * *' } | ||||
|     }) | ||||
|  | ||||
|     cluster.on('exit', (worker, code, signal) => { | ||||
|   | ||||
| @@ -1,26 +1,18 @@ | ||||
| 'use strict' | ||||
|  | ||||
| /* global wiki */ | ||||
|  | ||||
| const cluster = require('cluster') | ||||
| const _ = require('lodash') | ||||
| const fs = require('fs-extra') | ||||
| const path = require('path') | ||||
|  | ||||
| module.exports = { | ||||
|   loggers: {}, | ||||
|   init() { | ||||
|     let winston = require('winston') | ||||
|  | ||||
|     // Console | ||||
|  | ||||
|     let logger = new (winston.Logger)({ | ||||
|       level: wiki.config.logLevel, | ||||
|       transports: [ | ||||
|         new (winston.transports.Console)({ | ||||
|           level: wiki.config.logLevel, | ||||
|           prettyPrint: true, | ||||
|           colorize: true, | ||||
|           silent: false, | ||||
|           timestamp: true | ||||
|         }) | ||||
|       ] | ||||
|       transports: [] | ||||
|     }) | ||||
|  | ||||
|     logger.filters.push((level, msg) => { | ||||
| @@ -28,52 +20,20 @@ module.exports = { | ||||
|       return '[' + processName + '] ' + msg | ||||
|     }) | ||||
|  | ||||
|     // External services | ||||
|  | ||||
|     // if (wiki.config.externalLogging.bugsnag) { | ||||
|     //   const bugsnagTransport = require('./winston-transports/bugsnag') | ||||
|     //   logger.add(bugsnagTransport, { | ||||
|     //     level: 'warn', | ||||
|     //     key: wiki.config.externalLogging.bugsnag | ||||
|     //   }) | ||||
|     // } | ||||
|  | ||||
|     // if (wiki.config.externalLogging.loggly) { | ||||
|     //   require('winston-loggly-bulk') | ||||
|     //   logger.add(winston.transports.Loggly, { | ||||
|     //     token: wiki.config.externalLogging.loggly.token, | ||||
|     //     subdomain: wiki.config.externalLogging.loggly.subdomain, | ||||
|     //     tags: ['wiki-js'], | ||||
|     //     level: 'warn', | ||||
|     //     json: true | ||||
|     //   }) | ||||
|     // } | ||||
|  | ||||
|     // if (wiki.config.externalLogging.papertrail) { | ||||
|     //   require('winston-papertrail').Papertrail // eslint-disable-line no-unused-expressions | ||||
|     //   logger.add(winston.transports.Papertrail, { | ||||
|     //     host: wiki.config.externalLogging.papertrail.host, | ||||
|     //     port: wiki.config.externalLogging.papertrail.port, | ||||
|     //     level: 'warn', | ||||
|     //     program: 'wiki.js' | ||||
|     //   }) | ||||
|     // } | ||||
|  | ||||
|     // if (wiki.config.externalLogging.rollbar) { | ||||
|     //   const rollbarTransport = require('./winston-transports/rollbar') | ||||
|     //   logger.add(rollbarTransport, { | ||||
|     //     level: 'warn', | ||||
|     //     key: wiki.config.externalLogging.rollbar | ||||
|     //   }) | ||||
|     // } | ||||
|  | ||||
|     // if (wiki.config.externalLogging.sentry) { | ||||
|     //   const sentryTransport = require('./winston-transports/sentry') | ||||
|     //   logger.add(sentryTransport, { | ||||
|     //     level: 'warn', | ||||
|     //     key: wiki.config.externalLogging.sentry | ||||
|     //   }) | ||||
|     // } | ||||
|     _.forOwn(_.omitBy(wiki.config.logging.loggers, s => s.enabled === false), (loggerConfig, loggerKey) => { | ||||
|       let loggerModule = require(`../extensions/logging/${loggerKey}`) | ||||
|       loggerModule.init(logger, loggerConfig) | ||||
|       fs.readFile(path.join(wiki.ROOTPATH, `assets/svg/auth-icon-${loggerKey}.svg`), 'utf8').then(iconData => { | ||||
|         logger.icon = iconData | ||||
|       }).catch(err => { | ||||
|         if (err.code === 'ENOENT') { | ||||
|           logger.icon = '[missing icon]' | ||||
|         } else { | ||||
|           logger.error(err) | ||||
|         } | ||||
|       }) | ||||
|       this.loggers[logger.key] = loggerModule | ||||
|     }) | ||||
|  | ||||
|     return logger | ||||
|   } | ||||
|   | ||||
| @@ -29,7 +29,7 @@ module.exports = { | ||||
|         keyStream.on('end', resolve) | ||||
|       }) | ||||
|     }).then(() => { | ||||
|       wiki.logger.info('Purging old queue jobs: OK') | ||||
|       wiki.logger.info('Purging old queue jobs: [ OK ]') | ||||
|     }).return(true).catch(err => { | ||||
|       wiki.logger.error(err) | ||||
|     }) | ||||
|   | ||||
| @@ -21,7 +21,7 @@ module.exports = { | ||||
|     if (isPlainObject(wiki.config.redis)) { | ||||
|       let red = new Redis(wiki.config.redis) | ||||
|       red.on('ready', () => { | ||||
|         wiki.logger.info('Redis connection: OK') | ||||
|         wiki.logger.info('Redis connection: [ OK ]') | ||||
|       }) | ||||
|       red.on('error', () => { | ||||
|         wiki.logger.error('Failed to connect to Redis instance!') | ||||
|   | ||||
| @@ -1,20 +0,0 @@ | ||||
| 'use strict' | ||||
|  | ||||
| const util = require('util') | ||||
| const winston = require('winston') | ||||
| const _ = require('lodash') | ||||
|  | ||||
| let BugsnagLogger = winston.transports.BugsnagLogger = function (options) { | ||||
|   this.name = 'bugsnagLogger' | ||||
|   this.level = options.level || 'warn' | ||||
|   this.bugsnag = require('bugsnag') | ||||
|   this.bugsnag.register(options.key) | ||||
| } | ||||
| util.inherits(BugsnagLogger, winston.Transport) | ||||
|  | ||||
| BugsnagLogger.prototype.log = function (level, msg, meta, callback) { | ||||
|   this.bugsnag.notify(new Error(msg), _.assignIn(meta, { severity: level })) | ||||
|   callback(null, true) | ||||
| } | ||||
|  | ||||
| module.exports = BugsnagLogger | ||||
| @@ -1,20 +0,0 @@ | ||||
| 'use strict' | ||||
|  | ||||
| const util = require('util') | ||||
| const winston = require('winston') | ||||
| const _ = require('lodash') | ||||
|  | ||||
| let RollbarLogger = winston.transports.RollbarLogger = function (options) { | ||||
|   this.name = 'rollbarLogger' | ||||
|   this.level = options.level || 'warn' | ||||
|   this.rollbar = require('rollbar') | ||||
|   this.rollbar.init(options.key) | ||||
| } | ||||
| util.inherits(RollbarLogger, winston.Transport) | ||||
|  | ||||
| RollbarLogger.prototype.log = function (level, msg, meta, callback) { | ||||
|   this.rollbar.handleErrorWithPayloadData(new Error(msg), _.assignIn(meta, { level })) | ||||
|   callback(null, true) | ||||
| } | ||||
|  | ||||
| module.exports = RollbarLogger | ||||
| @@ -1,20 +0,0 @@ | ||||
| 'use strict' | ||||
|  | ||||
| const util = require('util') | ||||
| const winston = require('winston') | ||||
|  | ||||
| let SentryLogger = winston.transports.RollbarLogger = function (options) { | ||||
|   this.name = 'sentryLogger' | ||||
|   this.level = options.level || 'warn' | ||||
|   this.raven = require('raven') | ||||
|   this.raven.config(options.key).install() | ||||
| } | ||||
| util.inherits(SentryLogger, winston.Transport) | ||||
|  | ||||
| SentryLogger.prototype.log = function (level, msg, meta, callback) { | ||||
|   level = (level === 'warn') ? 'warning' : level | ||||
|   this.raven.captureMessage(msg, { level, extra: meta }) | ||||
|   callback(null, true) | ||||
| } | ||||
|  | ||||
| module.exports = SentryLogger | ||||
		Reference in New Issue
	
	Block a user