express-pino-logger
express-pino-logger copied to clipboard
How to avoid the entire request being logged every time using pino?
I am new to nodejs and decided to use the pino logger in my application. Here is the code snippet showing how I am using it:
const expressPino = require('express-pino-logger');
const { LOGLEVEL } = require('../config.js');
// Constructs a Pino Instance
const logger = pino({
level: LOGLEVEL || 'trace',
prettyPrint: { levelFirst: true, colorize: true, ignore: 'pid' },
});
// Construct an express middleware using the above pino instance
const expressLogger = expressPino({ logger });
module.exports = { logger, expressLogger };
Now, every time I do req.log.debug(config['abc']), the entire request body gets logged, thus making the logs very cumbersome to read. I tried changing the log levels but that doesn't help. Here is an example output:
DEBUG [1610445271782] (on blserver-org1): sku=FIN01 Query String req: { "id": 1, "method": "POST", "url": "/ifo_params?sku=FIN01", "headers": { "channel-name": "mychannel", "content-type": "application/json", "authorization": "Bearer eyJhbGciOiJSUzI1NiIsImtpZCI6IjVmOTcxMmEwODczMTcyMGQ2NmZkNGEyYTU5MmU0ZGZjMmI1ZGU1OTUiLCJ0eXAiOiJKV1QifQ.eyJvcmdJZCI6ImJ1eWVyMiIsImFkbWluIjp0cnVlLCJpc3MiOiJodHRwczovL3NlY3VyZXRva2VuLmdvb2dsZS5jb20vbWFya2V0c24tZGV2IiwiYXVkIjoibWFya2V0c24tZGV2IiwiYXV0aF90aW1lIjoxNjEwNDQ0ODU5LCJ1c2VyX2lkIjoibzBWZWl4VnJmZFJqbEdWZXlNS1p4Q052TkZSMiIsInN1YiI6Im8wVmVpeFZyZmRSamxHVmV5TUtaeENOdk5GUjIiLCJpYXQiOjE2MTA0NDQ4NTksImV4cCI6MTYxMDQ0ODQ1OSwiZW1haWwiOiJidXllcjJfYWRtaW5AbWFpbGluYXRvci5jb20iLCJlbWFpbF92ZXJpZmllZCI6ZmFsc2UsImZpcmViYXNlIjp7ImlkZW50aXRpZXMiOnsiZW1haWwiOlsiYnV5ZXIyX2FkbWluQG1haWxpbmF0b3IuY29tIl19LCJzaWduX2luX3Byb3ZpZGVyIjoicGFzc3dvcmQifX0.QlHxLrxcfxUmGK_Q193RdQSIBsoHly66CZDTWdRdyfZNAn-wH13el41ILnAj3YqVWgAFJY8u4BcFgZYePCujIO2gKFsM0WUs2M-a7CsMcDaWpqrQyVsfalRoYMDsk1DJypaevuKV8O4IbmdkgCbS8HmYO-dk99LRcwwYKs_vVnNBO4bTv5FFzMLh-DXrVfVBKk23Qem7JN5lX9UU6RZ-4WAVN-pN-TR5uRuF2koWjCoa90CKNhYOzKW1zeN904f1rCeuY0a4R4faFYMNAlkxslBpVSKaXCkSBXOSCjVykp611Ay6EQBkrpqbD1zHvv6eEfaaMyOzjlH3DzDye-vfMQ", "user-agent": "PostmanRuntime/7.26.8", "accept": "*/*", "cache-control": "no-cache", "postman-token": "aab26357-78ff-4899-8509-7918ca9a65c4", "host": "localhost:3000", "accept-encoding": "gzip, deflate, br", "connection": "keep-alive", "content-length": "114" } }
Can someone please tell me how to tell pino to not log the entire request every time.
These can be easly done by passing your own serializers. Also, it might be a good change to pino-http.
I've just run into this as well. It seems @types/pino-http
indicate you can pass the redact
option to pino-http
, but this has no effect. Seemingly because pino
doesn't support re-configuration?
I don't really understand how this relates to typescript. Note that @types/pino
are not maintained by us.