tesla icon indicating copy to clipboard operation
tesla copied to clipboard

Logger debug: true does nothing at runtime

Open tfwright opened this issue 10 months ago • 2 comments

Docs for Logger middleware say:

In order to be able to set :debug at runtime we can pass it as a option to the middleware at runtime.

So I expected to be able to toggle response logging on at off when configuring clients at runtime by configuring it like so: {Tesla.Middleware.Logger, debug: true}

But this does not appear to change logger behavior.

Since the docs also say something about the value of Logger level at compile time, I suspect what I am trying to do may not be possible currently? But it seems like it should be. My use case is that I don't normally want to log responses in prod, but sometimes I'd like to troubleshoot an issue by consoling in to that env.

tfwright avatar Apr 22 '24 22:04 tfwright

Using {Tesla.Middleware.Logger, debug: true} will call Logger.debug, but it will only show if your logger level is set to :debug (You can use Logger.configure(level: :debug) in console to change it)

teamon avatar Apr 23 '24 07:04 teamon

It looks like the issue was I had some incorrectly formatted headers that seemed to work for dispatching the actual request but were breaking logging: cannot truncate chardata because it contains something that is not valid chardata. When I changed the header keys from atoms to strings request logs started appearing again.

If that is indeed the issue, what do you think about prefacing that error message with something like "error rendering logs: " to make it a bit more clear that debug line is in place of where logs would have been emitted if not for the given error.

Beyond that, possible error when non-strings are passed in header data?

tfwright avatar Apr 23 '24 18:04 tfwright