From 6f9f53dd03bf684829d49564b4754c033d9abd5a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Garc=C3=ADa=20Aubert?= Date: Thu, 4 Jun 2020 20:28:06 +0200 Subject: [PATCH] Be able to reduce the footprint in the final log file depending on the environment --- lib/utils/logger.js | 7 ++++++- package-lock.json | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/utils/logger.js b/lib/utils/logger.js index 54beee2e..3acc1166 100644 --- a/lib/utils/logger.js +++ b/lib/utils/logger.js @@ -1,12 +1,17 @@ 'use strict'; const pino = require('pino'); -const { req: requestSerializer, res: responseSerializer, err: errorSerializer } = pino.stdSerializers; +const { req: requestSerializer, res: responseSerializer, err, wrapErrorSerializer } = pino.stdSerializers; +const DEV_ENVS = ['test', 'development']; module.exports = class Logger { constructor () { const { LOG_LEVEL, NODE_ENV } = process.env; const logLevelFromNodeEnv = NODE_ENV === 'test' ? 'fatal' : 'info'; + const errorSerializer = DEV_ENVS.includes(NODE_ENV) ? err : wrapErrorSerializer(err => { + err.stack = err.stack.split('\n').slice(0, 3).join('\n'); + return err; + }); const options = { base: null, // Do not bind hostname, pid and friends by default level: LOG_LEVEL || logLevelFromNodeEnv, diff --git a/package-lock.json b/package-lock.json index fe1e59de..580ad405 100644 --- a/package-lock.json +++ b/package-lock.json @@ -796,7 +796,7 @@ "integrity": "sha1-MvxLn82vhF/N9+c7uXysImHwqwo=" }, "camshaft": { - "version": "github:cartodb/camshaft#8d8f62d3d98b4ac316d8444ac3f3f321c28040dc", + "version": "github:cartodb/camshaft#633d3b85869d894d52ac5c9970462f326d2f42cc", "from": "github:cartodb/camshaft#dgaubert/ch78389/camshaft-replace-logger-from-bunyan-to-pino", "requires": { "async": "^1.5.2",