bithavoc / express-winston

express.js middleware for winstonjs
https://www.npmjs.com/package/express-winston
MIT License
796 stars 187 forks source link

Feature Request: costume response/request filter function #220

Closed vim-daniel closed 2 years ago

vim-daniel commented 4 years ago

I've came across the need to have parts of my response body written to the log, currently this library supports all or nothing, with dot notation support it will improve greatly as I will be able to pick specific parts of the body to log, but dot notation is not enough, I have for example a response body that contains an array of big objects and frankly I only want their ids to be logged, with dot notation that's impossible unfortunately.

It would be extremely helpful to control the response object that's gonna be written to the log at first i thought that requestFilter and responseFilter were exposed precisely for that, but they only control properties of the object, I propose changing these functions implementations (or deprecating them and creating new functions) that will be given the full object and their return value will be the object that will be written to the log

yinzara commented 4 years ago

The library has a "dynamicMeta" function option that if specified allows you to add arbitrary metadata programmatically to the log entry. See the "index.d.ts" for the signature but it's basically a function that takes in two arguments, the express request and express response and if it returns an object, its fields get added to the log entry metadata.