overleaf/libraries/logger/logging-manager.coffee

43 lines
1.1 KiB
CoffeeScript
Raw Normal View History

2014-02-17 09:54:20 -05:00
bunyan = require('bunyan')
module.exports = Logger =
initialize: (name) ->
@logger = bunyan.createLogger
name: name
serializers: bunyan.stdSerializers
return @
2015-06-16 11:50:18 -04:00
2015-12-08 05:30:18 -05:00
initializeErrorReporting: (sentry_dsn, options) ->
2015-06-16 11:50:18 -04:00
raven = require "raven"
2015-12-08 05:30:18 -05:00
@raven = new raven.Client(sentry_dsn, options)
2015-06-16 11:50:18 -04:00
2014-02-17 09:54:20 -05:00
info : ()->
@logger.info.apply(@logger, arguments)
log : ()->
@logger.info.apply(@logger, arguments)
2015-06-16 11:50:18 -04:00
error: (attributes, args...)->
@logger.error(attributes, args...)
if @raven?
error = attributes.err or attributes.error
req = attributes.req
2015-06-16 11:50:18 -04:00
if error?
tags = {}
extra = {}
for key, value of attributes
tags[key] = value if key.match(/_id/) and typeof value == 'string'
extra[key] = value
if req?
extra.req =
method: req.method
url: req.originalUrl
query: req.query
headers: req.headers
ip: req.ip
@raven.captureError(error, {tags: tags, extra: extra})
2014-02-17 09:54:20 -05:00
err: ()->
@logger.error.apply(@logger, arguments)
warn: ()->
@logger.warn.apply(@logger, arguments)
Logger.initialize("default-sharelatex")