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 bunyan = require('bunyan')
const request = require('request') 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 = { const Logger = module.exports = {
initialize(name) { initialize(name) {
@ -28,7 +43,11 @@ const Logger = module.exports = {
} }
this.logger = bunyan.createLogger({ this.logger = bunyan.createLogger({
name, name,
serializers: bunyan.stdSerializers, serializers: {
err: errSerializer,
req: bunyan.stdSerializers.req,
res: bunyan.stdSerializers.res
},
streams: loggerStreams streams: loggerStreams
}) })
if (this.isProduction) { if (this.isProduction) {

View file

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

View file

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