New API: avoid message formatting when possible to be able to take advantage of zero alloc libraries#11
New API: avoid message formatting when possible to be able to take advantage of zero alloc libraries#11hugoArregui wants to merge 3 commits intomasterfrom
Conversation
13f117b to
59705f5
Compare
Alternative API to avoid as much as possible string formatting and allow zero alloc libraries to be used as their fullest.
59705f5 to
a077066
Compare
Codecov Report
@@ Coverage Diff @@
## master #11 +/- ##
===========================================
- Coverage 55.46% 19.17% -36.29%
===========================================
Files 2 2
Lines 119 219 +100
===========================================
- Hits 66 42 -24
- Misses 51 169 +118
- Partials 2 8 +6
Continue to review full report at Codecov.
|
|
I might be doing things wrong but What do you think of including info from runtime? Getting the calling function could be really helpful for debugging. Right now people just grep for the error message. |
|
@Sean-Der sorry for the delay! I've been very busy with other things.
Sorry about that, yes, that's true, I should have clarified that, this change is backwards compatible with the usage of the logger, but not with a given logger implementation, so in this case the webrtc test is defining a custom a logger in a way this PR doesn't support anymore. Before this PR, you provide your own logger, but with this PR you provide a formatter. Let me know if you think this is a problem.
This is certainly doable, let me try something. I don't want to provide an API to do that because some log libraries support this functionality in their own way (zerolog and logrus for example), but I can add it to our default formatters. |
format: [filename:line] ..
|
@Sean-Der there you go: |
To work with golang1.13
42780f4 to
7661bb5
Compare
|
Oh I love that, nice work @hugoArregui This is a merge from me! We will need to communicate/update things a little more on this. Let me handle a few outstanding issues (that are actively biting people) and lets get this in right after! |
|
awesome! no hurry, this is a breaking change for people defining their own logger, so we can wait until the next major if that makes more sense |
|
I found this by way of #10 which I found when I encountered some evidence of logging introducing unnecessary mutex contention. It seems there are two orthogonal issues here and it's probably worth addressing them separately. (1) Suboptimal usage/invocation of logging libraries ( Issue (1) already has a solution in the stdlib and can be fixed fairly easily by auditing the codebase and using https://play.golang.org/p/Ius_-3qHErF Yields Issue (2) is a broader problem. Given that pion's goals are oriented around being embeddable, IMO this logging library should simply be a set of interfaces (https://dave.cheney.net/2017/01/23/the-package-level-logger-anti-pattern is a concise writeup on why) and a no-op default implementation leaving the concrete implementation up to users to inject. In addition, and tangentially related, I agree pion/webrtc and its transitive dependencies would benefit from structured logging and in particular something capable of supporting contextual fields so defining the interfaces as a subset of the zerolog API has my vote. That way injecting a logging implementation would only involve instantiating a zerolog Logger instead of the wrapper approach in this PR. |
|
@bshi I am 100% in support of this! It is also much easier to break these things now then in August 2019 (pre-Modules) back then I had some apprehension because breaking APIs caused so much frustration. |
|
Hey guys, it has been a while since I worked on this (and in go), so maybe I'm missing something, but the proposed logging package is a set of interfaces, there is also a zerolog package in the thirdparty directory, but is not all together. |
|
@hugoArregui sorry if I missed something but I don't see any interface types in this change? I was also mostly chiming in on what the interface should be. And I realized after the fact that the zerolog API surface is not amenable to hiding behind an interface without any changes. Should we consider a community standard interface? https://github.com/go-logr/logr supports contextual logging. |
|
Formatter is the interface: Line 67 in 7661bb5 logging/thirdparty/zerolog/logger.go Line 10 in 7661bb5 |
|
The interface as defined is still opinionated about the underlying logging mechanism (stdlib log). My initial point (as rationalized by https://dave.cheney.net/2017/01/23/the-package-level-logger-anti-pattern) was that pions should be entirely decoupled from any concrete logging implementation (aside from a nop-logger) and that logging should be injected by client code. |
Description
The idea is to deprecate the usage of string formatting and always use typed fields instead, so:
becomes:
This change is totally backwards compatible.
I also added a thirdparty directory with a zerolog implementation so people don't have to roll out their own implementation
This is how the integration will look like from a pion user perspective: https://github.com/decentraland/webrtc-broker/blob/5df08906d7547b5edbae3add274286a17f663f37/internal/logging/logging.go#L37
Reference issue
Related #10