Be able to reduce the footprint in the final log file depending on the environment

This commit is contained in:
Daniel García Aubert 2020-06-04 20:28:06 +02:00
parent 63bc8f75b9
commit 6f9f53dd03
2 changed files with 7 additions and 2 deletions

View File

@ -1,12 +1,17 @@
'use strict'; 'use strict';
const pino = require('pino'); 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 { module.exports = class Logger {
constructor () { constructor () {
const { LOG_LEVEL, NODE_ENV } = process.env; const { LOG_LEVEL, NODE_ENV } = process.env;
const logLevelFromNodeEnv = NODE_ENV === 'test' ? 'fatal' : 'info'; 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 = { const options = {
base: null, // Do not bind hostname, pid and friends by default base: null, // Do not bind hostname, pid and friends by default
level: LOG_LEVEL || logLevelFromNodeEnv, level: LOG_LEVEL || logLevelFromNodeEnv,

2
package-lock.json generated
View File

@ -796,7 +796,7 @@
"integrity": "sha1-MvxLn82vhF/N9+c7uXysImHwqwo=" "integrity": "sha1-MvxLn82vhF/N9+c7uXysImHwqwo="
}, },
"camshaft": { "camshaft": {
"version": "github:cartodb/camshaft#8d8f62d3d98b4ac316d8444ac3f3f321c28040dc", "version": "github:cartodb/camshaft#633d3b85869d894d52ac5c9970462f326d2f42cc",
"from": "github:cartodb/camshaft#dgaubert/ch78389/camshaft-replace-logger-from-bunyan-to-pino", "from": "github:cartodb/camshaft#dgaubert/ch78389/camshaft-replace-logger-from-bunyan-to-pino",
"requires": { "requires": {
"async": "^1.5.2", "async": "^1.5.2",