feat: Add JSON logging wrapper for STUNner
This PR adds a non-invasive JSON logging wrapper that converts STUNner's plain text logs to structured JSON format without modifying the STUNner codebase.
Key features:
- Zero code changes to STUNner required
- Uses slog to redirect standard log output to JSON
- Captures all Pion logging framework output
- Preserves rate limiting and log levels
- Production-ready implementation
Files added:
- cmd/stunner-wrapper/: Complete wrapper implementation
- Documentation and tests included
- Go version compatibility explained
The wrapper works by redirecting Go's standard log package to slog, which converts all log output to structured JSON format. Since STUNner uses the standard log package internally through Pion, this approach works without any modifications to the STUNner codebase.
Pull Request Test Coverage Report for Build 16568249087
Details
- 0 of 0 changed or added relevant lines in 0 files are covered.
- No unchanged relevant lines lost coverage.
- Overall coverage remained the same at 73.342%
| Totals | |
|---|---|
| Change from base Build 16018826374: | 0.0% |
| Covered Lines: | 1095 |
| Relevant Lines: | 1493 |
💛 - Coveralls
Thanks for bringing this up, this is a much requested feature.
Unfortunately the current approach is not acceptable for merging. Duplicating cmd/stunnerd/main.go essentially creates another parallel codepath to a key piece of STUNner code that we would need to separately maintain should we accept this PR, and given our current lack of resources this is definitely not something we want to do for now.
The correct approach would be to tackle this upstream in pion/logging. Actually it seems you've already tried that and get rejected due to Golang incompatibility. I'd recommend you keep pushing that PR since that's the right way to have this feature merged. The best would be to find some slog replacement that works with Golang v1.20 for the time pion is stuck at that version, and then transitioning to the official slog package once they make the switch upstream. You can also choose whatever structured logging lib you see fit that's compatible with Go 1.20 (we're using github.com/go-logr/logr in other projects with github.com/go-logr/zapr as the logging backend and it is working perfectly).
If you're absolutely failing on the upstream merge path you can also try to implement structured logging as a drop-in replacement for pkg/logger, we're using this wrapper around pion/logging everywhere. That will be somewhat limited in functionality though, given that we're building on the pion/logging interface.
Overall, I'm afraid whatever you do will be only a half-solution: pion/logging, and everything on top of it like STUNner, is built-around Printf style logging to format parameters, and the use of format strings is in fundamental violation of the philosophy of structured logging.
Anyway, thanks for pushing this, we truly appreciate your effort.
ps: Please exercise more care when trying to merge obviously AI-generated code into open source projects. (Judging from the excess use of emojis in your PR docs this must be Claude Sonnet or some variant.) Don't get me wrong, AI-generated code is perfectly fine with us, we're also using AIs all the time. But before submitting please make sure you properly review the code and remove all AI BS (like cmd/stunner-wrapper/GO_VERSION_COMPATIBILITY.md or cmd/stunner-wrapper/README.md in your PR).