Description
It's not an issue per se (although for me it definitely is, but it's not an Gin issue), I rather seek an advice, because I'm not able to find solution in Google.
So, I have a project using Gin, and I have some handlers responding to HTTP requests, and these handlers can use external libraries, and these libraries, being a black boxes for me, can panic at any point in time. Or, for that matter, it can be my own library and it can panic for whatever reason I wasn't able to predict.
Also, I use zerolog
for, well, logging something to an error log.
What I want is that any panic at all would be "automagically" logged in my error log, using zerolog as well (basically, I want to be able to invoke my piece of code with the panic text so that I will decide how exactly to log this panic).
What do I get in practice? There is nothing at all about the panic in my error log. I only see the last successful log.
And panic itself with the stacktrace I can see only in journalctl -xe
.
How do I log it instead, for a proper visibility?
Environment
- go version: 1.21.1
- gin version (or commit ref): 1.9.1
- operating system: debian 11
Comment From: zanmato
You can set the gin.DefaultWriter
and gin.DefaultErrorWriter
to use zerolog. If you need further customization you can customize both gin.Logger
and gin.Recovery
or even supply your own.
Comment From: skaurus
@zanmato Thanks, it helped!