morgan-body
morgan-body copied to clipboard
it is possible to get informations from request and add to the log?
I want add some informations that are passed thought the request object in log, this is possible?
@instplanet thank you for reaching out, do you mind being a bit more specific? It's not something that's part of the request or response body, correct?
Mind giving an example you'd like to work that doesn't now?
Let me explain better, i have a middleware that add some informations to my request like the following:
req.metadata = {
syncRegister: false,
collectionNamespaces: {
tenantCollection: credentials.mongoCredentials.dbName,
managerCollection: credentials.appConfiguraton.dbName,
pdvCollection: credentials.appConfiguraton.pdv_configuration.mongo_connection.database
},
accountId: decoded.accountId,
unitId: decoded.unitId,
requestOriginalUrl: req.originalUrl,
currentDate: getCurrentDate(),
requestId: req.id
}
this informations is very important because, with it, I can identify who is sending the request and would like to add it to log.
The problem is that this information is not passed on at the customer's request and I cannot return that information in the return request because it contains confidential information
let me know if I was not very clear with the explanation and thanks for your attention and help
got it, so basically you have a middleware before morgan-body
which adds to the req
object and you'd like to be able to log that...
btw, side note, just in case you didn't notice already, req.id
is actually already part of the logs.
okay I can imagine adding as an option an array of "additional custom properties on the request object to log" and logging in a way similar to request/response body. I would log these in order after the "request body" and before the "response body", sound good?
This sounds pretty good, will help me and others to customize log Thanks again for your attention and help
unfortunately I don't have time to work on this right now to the extent it deserved (this project is used quite a bit and needs to be tested) :(, I would gladly review a PR