[Spacetime] Use structured logging (log/slog)#1876
Closed
mrodm wants to merge 67 commits intoelastic:mainfrom
Closed
[Spacetime] Use structured logging (log/slog)#1876mrodm wants to merge 67 commits intoelastic:mainfrom
mrodm wants to merge 67 commits intoelastic:mainfrom
Conversation
mrodm
commented
May 31, 2024
internal/testrunner/testrunner.go
Outdated
Comment on lines
+290
to
+309
| type runnerLauncher struct { | ||
| logger *slog.Logger | ||
| } | ||
|
|
||
| func NewRunnerLauncher(options ...RunnerLauncherOption) *runnerLauncher { | ||
| r := runnerLauncher{logger: logger.Logger} | ||
| for _, opt := range options { | ||
| opt(&r) | ||
| } | ||
|
|
||
| return &r | ||
| } | ||
|
|
||
| type RunnerLauncherOption func(r *runnerLauncher) | ||
|
|
||
| func WithLogger(logger *slog.Logger) RunnerLauncherOption { | ||
| return func(r *runnerLauncher) { | ||
| r.logger = logger | ||
| } | ||
| } |
Contributor
Author
There was a problem hiding this comment.
Another option would be to set a new method in the TestRunner interface (e.g. SetLogger()), so it can be updated the logger of each runner dynamically.
Collaborator
💚 Build Succeeded
History
cc @mrodm |
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Currently,
elastic-packageuses a global logger based directly onlog.Printcalls: https://github.com/elastic/elastic-package/blob/486698806a279e44f7c6e03d896b9fa8e1cb1408/internal/logger/logger.goThis PR updates the code base to start using the new
log/slogpackage introduced in Go 1.21 (https://go.dev/blog/slog):log/slog.log, have been updated to run under the hood with an instance oflog/SlogLogger.-vflag, and now it can be set multiple times:-v: debug level-vv: trace level-vvv: adds source information (file, function and line of that log)--log-formatflag to set the format to be used in our logging:elastic-package test system -v --log-format [json|text|default]Space, Time
This project started during an ON Week, a time we give each other in Elastic to explore ideas or learn new things, in alignment with our Source Code.