replace bunyan error serializer with custom one (#14)

This commit is contained in:
Miguel Serrano 2019-07-11 12:11:09 +02:00 committed by GitHub
parent 888badbf0c
commit 6b3e7e4ffc
3 changed files with 22 additions and 2 deletions

View file

@ -1,5 +1,20 @@
const bunyan = require('bunyan')
const request = require('request')
const OError = require('@overleaf/o-error')
// bunyan error serializer
const errSerializer = function (err) {
if (!err || !err.stack)
return err;
return {
message: err.message,
name: err.name,
stack: OError.getFullStack(err),
info: OError.getFullInfo(err),
code: err.code,
signal: err.signal
};
};
const Logger = module.exports = {
initialize(name) {
@ -28,7 +43,11 @@ const Logger = module.exports = {
}
this.logger = bunyan.createLogger({
name,
serializers: bunyan.stdSerializers,
serializers: {
err: errSerializer,
req: bunyan.stdSerializers.req,
res: bunyan.stdSerializers.res
},
streams: loggerStreams
})
if (this.isProduction) {

View file

@ -14,6 +14,7 @@
"lint": "eslint -f unix ."
},
"dependencies": {
"@overleaf/o-error": "^2.0.0",
"bunyan": "1.8.12",
"raven": "1.1.3",
"request": "2.88.0"

View file

@ -28,7 +28,7 @@ describe('LoggingManager', function() {
once: sinon.stub().yields()
}
this.LoggingManager = SandboxedModule.require(modulePath, {
globals: { console },
globals: { console, process },
requires: {
bunyan: (this.Bunyan = {
createLogger: sinon.stub().returns(this.mockBunyanLogger),