How to log API calls and their errors

I have a service with some API calls. Sometimes these fail. In this case we call a view helper that renders the error in the required format and sets the HTTP status code.
These calls are logged with ExJsonLogger.Plug.Logger. However, only the status code and url etc are logged. I would like to log the error that the API endpoint produces as well. Also, I’d like to log an exception if one is raised. Right now it is logged, but not in the request log entry, so they require manual effort to correlate.

What is the best way of going about this?

1 Like