Procházet zdrojové kódy

replace bunyan error serializer with custom one (#14)

Miguel Serrano před 7 roky
rodič
revize
6b3e7e4ffc

+ 20 - 1
libraries/logger/logging-manager.js

@@ -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) {

+ 1 - 0
libraries/logger/package.json

@@ -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"

+ 1 - 1
libraries/logger/test/unit/loggingManagerTests.js

@@ -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),