-
Notifications
You must be signed in to change notification settings - Fork 103
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
adds std lib slog logger to knapsack #1419
adds std lib slog logger to knapsack #1419
Conversation
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.
(early thoughts)
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.
This feels like it's taking a reasonable shape
cmd/launcher/launcher.go
Outdated
// system log | ||
k.AddReplaceSlogHandler("system", slog.NewJSONHandler(os.Stderr, &slog.HandlerOptions{ |
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.
This probably won't work for windows.
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.
this is looking pretty good.
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 think we could ship this. Sweet!
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.
Woo! Looks like a good base
case "error": | ||
ls.slogLevel.Set(slog.LevelError) | ||
case "default": | ||
ls.knapsack.Slogger().Error("unrecognized flag value for log shipping level", |
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.
Ha! I love that we can use knapsack.Slogger here.
This PR add a std lib slog logger to knapsack accessible via
Knapsack.Slogger()
andKnapsack.SystemSlogger()
. The knapsack logger writes to all the same destinations as our existing loggers. To do this I had to expose the writers in various places to pass to slog log handlers. It's kinda weird, but I couldn't find a better way.The stdlib does not include any support for tee logging. So to achieve something similar you can have a single logger write to multiple handlers or more accurately give the logger a handler that will fan out to other handlers. We could write our own handler to do this, but I found a sufficient one here.
We could do more advanced things with these handlers like determining if we want to send debug logs based on log attributes ie. only ship debug logs for nababe. However, to reduce complexity of the PR, I didn't add any fancy stuff.
Tested that logging works for:
Example slog output