Be able to reduce the footprint in the final log file depending on the environment
This commit is contained in:
parent
63bc8f75b9
commit
6f9f53dd03
@ -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
2
package-lock.json
generated
@ -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",
|
||||||
|
Loading…
Reference in New Issue
Block a user