Skip to content
This repository has been archived by the owner on Dec 15, 2022. It is now read-only.

Log the req/res body #24

Closed
cvburgess opened this issue Oct 8, 2018 · 11 comments
Closed

Log the req/res body #24

cvburgess opened this issue Oct 8, 2018 · 11 comments

Comments

@cvburgess
Copy link

Hey there!

This lib is quite excellent.

Only issue: I'd love to log the req and res bodies as they contain useful information.

What is the desired way of doing this?

@mcollina
Copy link
Member

mcollina commented Oct 8, 2018

we don't log them because they could be quite big. They are also very likely to contain personal information you might not want to log anyway. You can just log them yourself req.log.info({ body }).

@cvburgess
Copy link
Author

thank you, it would be nice as an option for scenarios where you know what the bodies should contain ( like internal microservices )

@batjko
Copy link

batjko commented Jan 29, 2019

Same here. I would like to at least have the option, say, in order to hook in and log out the number of records returned.

You can just log them yourself req.log.info({ body }).

e.g. where does body come from in this example? Does the express logger expose this directly, or do I need to define a second middleware function that pulls it from the response object?

@davidmarkclements
Copy link
Member

You’d need a second middleware function.

PRs are always welcome - in this case an option that enables the body and always encourages the use of the redact option would be ideal

@naseemkullah
Copy link

Would the PR be in the pino-http repo or in this repo? I am a bit confused by the existence of the two

@mcollina
Copy link
Member

pino-http, thanks!

@Sof31t
Copy link

Sof31t commented Jan 10, 2020

@mcollina I think giving the user the possibility to choose whatever he wants to log is important. In my use case, I don't have any huge request bodies, I want to be able to automatically log all of them. I prefer not to have more than one log for each request. Also, for sensitive information, we should be able to hide them 😄

@naseemkullah
Copy link

pinojs/pino-http#76 created which adds the example as how to achieve logging req body

@Phunky
Copy link

Phunky commented Sep 4, 2020

@naseemkullah when trying to apply this example to express-pino-logger the request body does not seem to be available.

Ignore me, the ordering of my middleware was off.

@ryan6416
Copy link

ryan6416 commented Nov 2, 2021

@naseemkullah do you have an example of logging the response body? pinojs/pino-http#173

@naseemkullah
Copy link

@ryan-efendy answered in pinojs/pino-http#173

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants