Browse Source

Added sentry.io logger option

NGPixel 8 years ago
parent
commit
d13085ac1b
5 changed files with 31 additions and 3 deletions
  1. 2 1
      CHANGELOG.md
  2. 1 0
      config.sample.yml
  3. 8 0
      libs/logger.js
  4. 20 0
      libs/winston-transports/sentry.js
  5. 0 2
      server.js

+ 2 - 1
CHANGELOG.md

@@ -7,7 +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
+- Logs: Support for the logging services: Bugsnag, Loggly, Papertrail, Rollbar and Sentry
 
 ### Changed
 - Native Compilation Removal: Replaced farmhash with md5
@@ -16,6 +16,7 @@ This project adheres to [Semantic Versioning](http://semver.org/).
 - Sidebar: Contents is now Page Contents
 - Sidebar: Start is now Top of Page
 - UI: Content headers are now showing an anchor icon instead of a #
+- Dev: Replaced Gulp with Fuse-box
 
 ### Fixed
 - Auth: Authentication would fail if email has uppercase chars and provider callback is in lowercase

+ 1 - 0
config.sample.yml

@@ -141,4 +141,5 @@ externalLogging:
   loggly: false
   papertrail: false
   rollbar: false
+  sentry: false
 

+ 8 - 0
libs/logger.js

@@ -60,5 +60,13 @@ module.exports = (isDebug) => {
     })
   }
 
+  if (appconfig.externalLogging.sentry) {
+    const sentryTransport = require('./winston-transports/sentry')
+    winston.add(sentryTransport, {
+      level: 'warn',
+      key: appconfig.externalLogging.sentry
+    })
+  }
+
   return winston
 }

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

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

+ 0 - 2
server.js

@@ -212,8 +212,6 @@ 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!')
 })
 
 // ----------------------------------------