saloonphp / saloon

🤠 Build beautiful API integrations and SDKs with Saloon
https://docs.saloon.dev
MIT License
2.09k stars 107 forks source link

Log request and response #325

Closed UnbekanntesPferd closed 1 year ago

UnbekanntesPferd commented 1 year ago

Hi! I want to log every request and response of a connector. To just log the request I could use something like in the example, but at that early stage there is no response. Do we have any hook or event that can be used to log request, response and maybe even more information from guzzle (e.g. request time) in one method?

gdebrauwer commented 1 year ago

You could use debugRequest and debugResponse methods on a connector I think: https://docs.saloon.dev/digging-deeper/debugging

UnbekanntesPferd commented 1 year ago

My understanding of those methods is, that they are more or less a wrapper for the onRequest/onResponse middleware methods. So in this case I would again only be able to log just the request or just the response. Or am I wrong?

It would be enough to have information about the request somewhere in "onResponse", I would say. But it seems it's not there.

gdebrauwer commented 1 year ago

the $response parameter you receive in debugResponse closure is a saloon response class and that class has getRequest()/getPendingRequest()/getPsrRequest() methods

UnbekanntesPferd commented 1 year ago

That was way easier than expected. Thanks a lot! 👍

Sammyjo20 commented 1 year ago

Thanks for the response @gdebrauwer! Yep this is a good way of logging.