Shortcuts for serializers

This commit is contained in:
Daniel García Aubert 2020-06-03 15:10:31 +02:00
parent 1e89821d97
commit 219d2c9044

View File

@ -1,6 +1,7 @@
'use strict';
const pino = require('pino');
const { req: requestSerializer, res: responseSerializer, err: errorSerializer } = pino.stdSerializers;
module.exports = class Logger {
constructor () {
@ -10,9 +11,9 @@ module.exports = class Logger {
base: null, // Do not bind hostname, pid and friends by default
level: LOG_LEVEL || logLevelFromNodeEnv,
serializers: {
request: pino.stdSerializers.req,
response: pino.stdSerializers.res,
errors: (errors) => errors.map((err) => pino.stdSerializers.err(err))
request: requestSerializer,
response: responseSerializer,
errors: (errors) => errors.map((err) => errorSerializer(err))
}
};
const dest = pino.destination({ sync: false }); // stdout