-
Notifications
You must be signed in to change notification settings - Fork 49
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Experimental: zap backend for go-log #61
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
279345f
Zap!!
Kubuxu a90b27e
Deprecate Warning and Warningf
Kubuxu 4baffa2
Removed why/logging
Kubuxu 7bfb9a1
Expose Zap
Kubuxu 079c202
Address review
Kubuxu 92024ec
Address review
Kubuxu 167d6d4
Return without changing log level if level is invalid
Kubuxu 129fa80
Cleanup stringToZap
Kubuxu c5f3474
Remove unused code
Kubuxu fec3878
Typed levels
Kubuxu 2ca2427
add godocs.
raulk 2b4e426
update deps and regen go.sum.
raulk File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package log | ||
|
||
import "go.uber.org/zap/zapcore" | ||
|
||
// LogLevel represents a log severity level. Use the package variables as an | ||
// enum. | ||
type LogLevel zapcore.Level | ||
|
||
var ( | ||
LevelDebug = LogLevel(zapcore.DebugLevel) | ||
LevelInfo = LogLevel(zapcore.InfoLevel) | ||
LevelWarn = LogLevel(zapcore.WarnLevel) | ||
LevelError = LogLevel(zapcore.ErrorLevel) | ||
LevelDPanic = LogLevel(zapcore.DPanicLevel) | ||
LevelPanic = LogLevel(zapcore.PanicLevel) | ||
LevelFatal = LogLevel(zapcore.FatalLevel) | ||
) | ||
|
||
// LevelFromString parses a string-based level and returns the corresponding | ||
// LogLevel. | ||
// | ||
// Supported strings are: DEBUG, INFO, WARN, ERROR, DPANIC, PANIC, FATAL, and | ||
// their lower-case forms. | ||
// | ||
// The returned LogLevel must be discarded if error is not nil. | ||
func LevelFromString(level string) (LogLevel, error) { | ||
lvl := zapcore.InfoLevel // zero value | ||
err := lvl.Set(level) | ||
return LogLevel(lvl), err | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the plan to eventually switch to zap directly? It seems odd to hard-code zap into this library and expose it like this if that isn't the case.
However, if that is the case, we should have a migration plan in place to get rid of the facade.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Zap's interface is big but very useful for structured logging. I don't see any benefit of writing a full interface facade for it (it won't allow us to switch to something else easier).
The migration is mostly limited to stopping the use of deprecated functions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But is there a plan to eventually drop this library and directly depend on Zap.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I too was in the camp that logging is so pervasive that we shouldn't introduce indirections. Also, changing the logging backend happens once in a blue moon -- so it's a questionable risk/reward gradient. However, there are some legit use cases where you'd want to replace the logging backend with something else, e.g. WASM runtimes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, as Zap doesn't provide centralised log level facilities.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess we'd do that using build tags anyway. As long as the callers don't need to reference zap or zapcore explicitly, we should be able to mimic its public API?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can change how logging is done for WASM by changing formatters and outputs in Zap.
Problem with mimicking Zap's API is that they are at least 93 functions we would have to define.
In some cases (performance) one would use
zap.Field
and connected functions to achieve 0-overhead structured logging.