I tend to use printf-style debugging as my primary troubleshooting method and only resort to gdb as a last resort.
While I like its ease of use printf debugging isn't without its annoyances, namely removing the print statements once you're done.
I used to use trace-level logging from proper logging libraries but adding trace calls in every corner quickly gets out of control and results in an overwhelming amount of output.
To scratch my own itch I created dlg - a minimal debugging library that disappears completely from production builds. Its API exposes just a single function, Printf [1].
dlg is optimized for performance in debug builds and, most importantly, when compiled without the dlg build tag, all calls are eliminated by the Go linker as if dlg was never imported.
For debug builds it adds optional stack trace generation configurable via environment variables or linker flags.
GitHub: https://github.com/vvvvv/dlg
Any feedback is much appreciated.
[1]: Actually two functions - there's also SetOutput.
kitd•6mo ago
Just one thought: I don't think your stack traces need to include the lines inside Printf itself and it adds to the noise a bit. Maybe just go up to the line where the call to Printf is made?
0xFEE1DEAD•6mo ago
You're absolutely right, it annoys me as well.
It's a bit finicky to do so, but I'm currently in an exploratory phase of providing an even more fine grained stack tracing feature and filtering out dlg itself is definitly on my todo list.