ソースを参照

Added support for 4 logging services

NGPixel 8 年 前
コミット
df4da74539

+ 3 - 0
.gitignore

@@ -41,6 +41,9 @@ jspm_packages
 # Optional REPL history
 # Optional REPL history
 .node_repl_history
 .node_repl_history
 
 
+# NewRelic APM
+newrelic.js
+
 # Fusebox
 # Fusebox
 .fusebox
 .fusebox
 
 

+ 1 - 0
CHANGELOG.md

@@ -7,6 +7,7 @@ This project adheres to [Semantic Versioning](http://semver.org/).
 - Interactive setup
 - Interactive setup
 - Auth: GitHub and Slack authentication providers are now available
 - Auth: GitHub and Slack authentication providers are now available
 - Auth: LDAP authentication provider is now available
 - Auth: LDAP authentication provider is now available
+- Logs: Support for the logging services: Bugsnag, Loggly, Papertrail and Rollbar
 
 
 ### Changed
 ### Changed
 - Native Compilation Removal: Replaced farmhash with md5
 - Native Compilation Removal: Replaced farmhash with md5

+ 5 - 0
app/data.yml

@@ -50,6 +50,11 @@ defaults:
       signature:
       signature:
         name: Wiki
         name: Wiki
         email: wiki@example.com
         email: wiki@example.com
+    externalLogging:
+      bugsnap: false
+      loggly: false
+      papertrail: false
+      rollbar: false
 langs:
 langs:
   -
   -
     id: en
     id: en

ファイルの差分が大きいため隠しています
+ 0 - 6
assets/js/bundle.min.js


ファイルの差分が大きいため隠しています
+ 53 - 0
assets/js/configure.min.js


+ 4 - 0
client/configure.js

@@ -0,0 +1,4 @@
+'use strict'
+
+require('./scss/configure.scss')
+require('./js/configure.js')

+ 0 - 4
client/index.js

@@ -7,10 +7,6 @@ switch (logic) {
     require('./scss/login.scss')
     require('./scss/login.scss')
     require('./js/login.js')
     require('./js/login.js')
     break
     break
-  case 'configure':
-    require('./scss/configure.scss')
-    require('./js/configure.js')
-    break
   default:
   default:
     require('./node_modules/highlight.js/styles/tomorrow.css')
     require('./node_modules/highlight.js/styles/tomorrow.css')
     require('./node_modules/simplemde/dist/simplemde.min.css')
     require('./node_modules/simplemde/dist/simplemde.min.css')

+ 11 - 0
config.sample.yml

@@ -131,3 +131,14 @@ git:
   signature:
   signature:
     name: Marty
     name: Marty
     email: marty@example.com
     email: marty@example.com
+
+# ---------------------------------------------------------------------
+# External Logging
+# ---------------------------------------------------------------------
+
+externalLogging:
+  bugsnag: false
+  loggly: false
+  papertrail: false
+  rollbar: false
+

+ 70 - 34
fuse.js

@@ -19,10 +19,9 @@ const args = require('yargs')
       type: 'boolean'
       type: 'boolean'
     })
     })
     .option('c', {
     .option('c', {
-      alias: 'configure',
-      describe: 'Use Configure mode',
-      type: 'boolean',
-      implies: 'd'
+      alias: 'dev-configure',
+      describe: 'Start in Configure Developer mode',
+      type: 'boolean'
     })
     })
     .help('h')
     .help('h')
     .alias('h', 'help')
     .alias('h', 'help')
@@ -62,34 +61,66 @@ if (args.d) {
   // Server
   // Server
 
 
   _.delay(() => {
   _.delay(() => {
-    if (args.c) {
-      nodemon({
-        exec: 'node wiki configure',
-        ignore: ['assets/', 'client/', 'data/', 'repo/', 'tests/'],
-        ext: 'js json',
-        watch: [
-          'configure.js'
-        ],
-        env: { 'NODE_ENV': 'development' }
-      })
-    } else {
-      nodemon({
-        script: './server.js',
-        args: [],
-        ignore: ['assets/', 'client/', 'data/', 'repo/', 'tests/'],
-        ext: 'js json',
-        watch: [
-          'controllers',
-          'libs',
-          'locales',
-          'middlewares',
-          'models',
-          'agent.js',
-          'server.js'
-        ],
-        env: { 'NODE_ENV': 'development' }
-      })
-    }
+    nodemon({
+      script: './server.js',
+      args: [],
+      ignore: ['assets/', 'client/', 'data/', 'repo/', 'tests/'],
+      ext: 'js json',
+      watch: [
+        'controllers',
+        'libs',
+        'locales',
+        'middlewares',
+        'models',
+        'agent.js',
+        'server.js'
+      ],
+      env: { 'NODE_ENV': 'development' }
+    })
+  }, 1000)
+} else if (args.c) {
+  // =============================================
+  // DEVELOPER MODE
+  // =============================================
+
+  console.info(colors.bgWhite.black(' Starting Fuse in CONFIGURE DEVELOPER mode... '))
+
+  const nodemon = require('nodemon')
+
+  // Client
+
+  const fuse = fsbx.FuseBox.init({
+    homeDir: './client',
+    outFile: './assets/js/configure.min.js',
+    alias: {
+      vue: 'vue/dist/vue.js'
+    },
+    plugins: [
+      [ fsbx.SassPlugin({ includePaths: ['../core'] }), fsbx.CSSPlugin() ],
+      fsbx.BabelPlugin({ comments: false, presets: ['es2015'] }),
+      fsbx.JSONPlugin()
+    ],
+    debug: false,
+    log: true
+  })
+
+  fuse.devServer('>configure.js', {
+    port: 4444,
+    httpServer: false
+  })
+
+  // Server
+
+  _.delay(() => {
+    nodemon({
+      exec: 'node wiki configure',
+      ignore: ['assets/', 'client/', 'data/', 'repo/', 'tests/'],
+      ext: 'js json',
+      watch: [
+        'configure.js'
+      ],
+      env: { 'NODE_ENV': 'development' }
+    })
   }, 1000)
   }, 1000)
 } else {
 } else {
   // =============================================
   // =============================================
@@ -100,7 +131,9 @@ if (args.d) {
 
 
   const fuse = fsbx.FuseBox.init({
   const fuse = fsbx.FuseBox.init({
     homeDir: './client',
     homeDir: './client',
-    outFile: './assets/js/bundle.min.js',
+    alias: {
+      vue: 'vue/dist/vue.js'
+    },
     plugins: [
     plugins: [
       [ fsbx.SassPlugin({ outputStyle: 'compressed', includePaths: ['./node_modules/requarks-core'] }), fsbx.CSSPlugin() ],
       [ fsbx.SassPlugin({ outputStyle: 'compressed', includePaths: ['./node_modules/requarks-core'] }), fsbx.CSSPlugin() ],
       fsbx.BabelPlugin({
       fsbx.BabelPlugin({
@@ -118,7 +151,10 @@ if (args.d) {
     log: true
     log: true
   })
   })
 
 
-  fuse.bundle('>index.js').then(() => {
+  fuse.bundle({
+    './assets/js/bundle.min.js': '>index.js',
+    './assets/js/configure.min.js': '>configure.js'
+  }).then(() => {
     console.info(colors.green.bold('Assets compilation + bundling completed.'))
     console.info(colors.green.bold('Assets compilation + bundling completed.'))
   }).catch(err => {
   }).catch(err => {
     console.error(colors.green.red(' X Bundle compilation failed! ' + err.message))
     console.error(colors.green.red(' X Bundle compilation failed! ' + err.message))

+ 64 - 0
libs/logger.js

@@ -0,0 +1,64 @@
+'use strict'
+
+const winston = require('winston')
+
+module.exports = (isDebug) => {
+  if (typeof PROCNAME === 'undefined') {
+    const PROCNAME = 'SERVER' // eslint-disable-line no-unused-vars
+  }
+
+  // Console + File Logs
+
+  winston.remove(winston.transports.Console)
+  winston.add(winston.transports.Console, {
+    level: (isDebug) ? 'debug' : 'info',
+    prettyPrint: true,
+    colorize: true,
+    silent: false,
+    timestamp: true,
+    filters: [(level, msg, meta) => {
+      return '[' + PROCNAME + '] ' + msg // eslint-disable-line no-undef
+    }]
+  })
+
+  // External services
+
+  if (appconfig.externalLogging.bugsnag) {
+    const bugsnagTransport = require('./winston-transports/bugsnag')
+    winston.add(bugsnagTransport, {
+      level: 'warn',
+      key: appconfig.externalLogging.bugsnag
+    })
+  }
+
+  if (appconfig.externalLogging.loggly) {
+    require('winston-loggly-bulk')
+    winston.add(winston.transports.Loggly, {
+      token: appconfig.externalLogging.loggly.token,
+      subdomain: appconfig.externalLogging.loggly.subdomain,
+      tags: ['wiki-js'],
+      level: 'warn',
+      json: true
+    })
+  }
+
+  if (appconfig.externalLogging.papertrail) {
+    require('winston-papertrail').Papertrail // eslint-disable-line no-unused-expressions
+    winston.add(winston.transports.Papertrail, {
+      host: appconfig.externalLogging.papertrail.host,
+      port: appconfig.externalLogging.papertrail.port,
+      level: 'warn',
+      program: 'wiki.js'
+    })
+  }
+
+  if (appconfig.externalLogging.rollbar) {
+    const rollbarTransport = require('./winston-transports/rollbar')
+    winston.add(rollbarTransport, {
+      level: 'warn',
+      key: appconfig.externalLogging.rollbar
+    })
+  }
+
+  return winston
+}

+ 20 - 0
libs/winston-transports/bugsnag.js

@@ -0,0 +1,20 @@
+'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

+ 20 - 0
libs/winston-transports/rollbar.js

@@ -0,0 +1,20 @@
+'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 - 1
package.json

@@ -8,7 +8,7 @@
     "stop": "node wiki stop",
     "stop": "node wiki stop",
     "build": "node fuse",
     "build": "node fuse",
     "dev": "node fuse -d",
     "dev": "node fuse -d",
-    "dev-configure": "node fuse -d -c",
+    "dev-configure": "node fuse -c",
     "test": "jest",
     "test": "jest",
     "snyk-protect": "snyk protect",
     "snyk-protect": "snyk protect",
     "__prepublish": "npm run snyk-protect",
     "__prepublish": "npm run snyk-protect",

+ 11 - 4
server.js

@@ -11,22 +11,27 @@ global.ROOTPATH = __dirname
 global.IS_DEBUG = process.env.NODE_ENV === 'development'
 global.IS_DEBUG = process.env.NODE_ENV === 'development'
 global.CORE_PATH = (IS_DEBUG) ? ROOTPATH + '/../core/' : ROOTPATH + '/node_modules/requarks-core/'
 global.CORE_PATH = (IS_DEBUG) ? ROOTPATH + '/../core/' : ROOTPATH + '/node_modules/requarks-core/'
 
 
+if (IS_DEBUG) {
+  try { require('newrelic') } catch (err) {}
+}
+
 process.env.VIPS_WARNING = false
 process.env.VIPS_WARNING = false
 
 
+let appconf = require(CORE_PATH + 'core-libs/config')()
+global.appconfig = appconf.config
+global.appdata = appconf.data
+
 // ----------------------------------------
 // ----------------------------------------
 // Load Winston
 // Load Winston
 // ----------------------------------------
 // ----------------------------------------
 
 
-global.winston = require(CORE_PATH + 'core-libs/winston')(IS_DEBUG)
+global.winston = require('./libs/logger')(IS_DEBUG)
 winston.info('[SERVER] Wiki.js is initializing...')
 winston.info('[SERVER] Wiki.js is initializing...')
 
 
 // ----------------------------------------
 // ----------------------------------------
 // Load global modules
 // Load global modules
 // ----------------------------------------
 // ----------------------------------------
 
 
-let appconf = require(CORE_PATH + 'core-libs/config')()
-global.appconfig = appconf.config
-global.appdata = appconf.data
 global.lcdata = require('./libs/local').init()
 global.lcdata = require('./libs/local').init()
 global.db = require(CORE_PATH + 'core-libs/mongodb').init()
 global.db = require(CORE_PATH + 'core-libs/mongodb').init()
 global.entries = require('./libs/entries').init()
 global.entries = require('./libs/entries').init()
@@ -207,6 +212,8 @@ server.on('error', (error) => {
 
 
 server.on('listening', () => {
 server.on('listening', () => {
   winston.info('[SERVER] HTTP/WS server started successfully! [RUNNING]')
   winston.info('[SERVER] HTTP/WS server started successfully! [RUNNING]')
+  winston.warn('Something went wrong!')
+  winston.error('An big error occured!')
 })
 })
 
 
 // ----------------------------------------
 // ----------------------------------------

+ 1 - 1
views/configure/index.pug

@@ -10,7 +10,7 @@ html(data-logic='configure')
       link(rel='icon', type='image/png', sizes=favsize + 'x' + favsize, href='/favicons/favicon-' + favsize + 'x' + favsize + '.png')
       link(rel='icon', type='image/png', sizes=favsize + 'x' + favsize, href='/favicons/favicon-' + favsize + 'x' + favsize + '.png')
 
 
     // JS / CSS
     // JS / CSS
-    script(type='text/javascript', src='/js/bundle.min.js')
+    script(type='text/javascript', src='/js/configure.min.js')
 
 
     block head
     block head
 
 

この差分においてかなりの量のファイルが変更されているため、一部のファイルを表示していません