Browse Source

Added support for 4 logging services

pull/73/head
NGPixel 7 years ago
parent
commit
df4da74539
15 changed files with 67291 additions and 27030 deletions
  1. 3
      .gitignore
  2. 1
      CHANGELOG.md
  3. 5
      app/data.yml
  4. 47788
      assets/js/bundle.min.js
  5. 46278
      assets/js/configure.min.js
  6. 4
      client/configure.js
  7. 4
      client/index.js
  8. 11
      config.sample.yml
  9. 104
      fuse.js
  10. 64
      libs/logger.js
  11. 20
      libs/winston-transports/bugsnag.js
  12. 20
      libs/winston-transports/rollbar.js
  13. 2
      package.json
  14. 15
      server.js
  15. 2
      views/configure/index.pug

3
.gitignore

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

1
CHANGELOG.md

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

5
app/data.yml

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

47788
assets/js/bundle.min.js
File diff suppressed because it is too large
View File

46278
assets/js/configure.min.js
File diff suppressed because it is too large
View File

4
client/configure.js

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

4
client/index.js

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

11
config.sample.yml

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

104
fuse.js

@ -19,10 +19,9 @@ const args = require('yargs')
type: 'boolean'
})
.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')
.alias('h', 'help')
@ -62,34 +61,66 @@ if (args.d) {
// Server
_.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)
} else {
// =============================================
@ -100,7 +131,9 @@ if (args.d) {
const fuse = fsbx.FuseBox.init({
homeDir: './client',
outFile: './assets/js/bundle.min.js',
alias: {
vue: 'vue/dist/vue.js'
},
plugins: [
[ fsbx.SassPlugin({ outputStyle: 'compressed', includePaths: ['./node_modules/requarks-core'] }), fsbx.CSSPlugin() ],
fsbx.BabelPlugin({
@ -118,7 +151,10 @@ if (args.d) {
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.'))
}).catch(err => {
console.error(colors.green.red(' X Bundle compilation failed! ' + err.message))

64
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
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
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

2
package.json

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

15
server.js

@ -11,22 +11,27 @@ global.ROOTPATH = __dirname
global.IS_DEBUG = process.env.NODE_ENV === 'development'
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
let appconf = require(CORE_PATH + 'core-libs/config')()
global.appconfig = appconf.config
global.appdata = appconf.data
// ----------------------------------------
// 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...')
// ----------------------------------------
// 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.db = require(CORE_PATH + 'core-libs/mongodb').init()
global.entries = require('./libs/entries').init()
@ -207,6 +212,8 @@ server.on('error', (error) => {
server.on('listening', () => {
winston.info('[SERVER] HTTP/WS server started successfully! [RUNNING]')
winston.warn('Something went wrong!')
winston.error('An big error occured!')
})
// ----------------------------------------

2
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')
// JS / CSS
script(type='text/javascript', src='/js/bundle.min.js')
script(type='text/javascript', src='/js/configure.min.js')
block head

Loading…
Cancel
Save