-
Notifications
You must be signed in to change notification settings - Fork 353
refactor: replace logrus for global slog logger #889
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
Merged
Merged
Changes from 8 commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
851e42f
refactor: replace logrus for global slog logger
rogercoll 7a0d52f
Merge branch 'main' into set_global_logger
rogercoll 0c99916
set default info level and remove file source
rogercoll b98c85b
remove logrus license
rogercoll 530d0ce
Merge branch 'main' into set_global_logger
rogercoll 586fdee
fix: ebpf amd blog
rogercoll 49353b6
fix: coredump logger usage
rogercoll 2facbb6
fix non constant strings
rogercoll fc2c5f6
Update internal/global/logging.go
rogercoll 4eadd9f
Update internal/global/logging.go
rogercoll b2c88d2
Update internal/global/logging.go
rogercoll 7f23a13
add helper function to set Debug global logger
rogercoll 82d98d5
map log.Printf statements to Info level
rogercoll 1064fd2
Merge branch 'main' into set_global_logger
rogercoll 49405a2
fix non-constant string
rogercoll 6c29f67
refactor: move global package to log
rogercoll 2ce403c
Merge branch 'main' into set_global_logger
rogercoll 1a5537f
Merge branch 'main' into set_global_logger
rogercoll 74824b3
Update collector/factory.go
rogercoll 64f9b21
Update internal/global/log/logging.go
rogercoll 1236b9c
remove global level path
rogercoll 6861c47
Merge branch 'main' into set_global_logger
rogercoll 853ae6e
Merge branch 'main' into set_global_logger
rogercoll 2e0ed68
fix: integration tests debug log
rogercoll 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 was deleted.
Oops, something went wrong.
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
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,95 @@ | ||
| package global // import "go.opentelemetry.io/ebpf-profiler/internal/global" | ||
|
|
||
| import ( | ||
| "fmt" | ||
| "log/slog" | ||
| "os" | ||
| "sync/atomic" | ||
| ) | ||
|
|
||
| // globalLogger holds a reference to the [slog.Logger] used within | ||
| // go.opentelemetry.io/otel. | ||
rogercoll marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| // | ||
| // The default logger uses stdr which is backed by the standard `log.Logger` | ||
rogercoll marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| // interface. This logger will show messages at the Info Level. | ||
| var globalLogger = func() *atomic.Pointer[slog.Logger] { | ||
| l := slog.New(slog.NewTextHandler(os.Stderr, &slog.HandlerOptions{ | ||
| Level: slog.LevelInfo, | ||
| })) | ||
|
|
||
| p := new(atomic.Pointer[slog.Logger]) | ||
| p.Store(l) | ||
| return p | ||
| }() | ||
|
|
||
| // SetLogger sets the global Logger to l. | ||
| func SetLogger(l slog.Logger) { | ||
| globalLogger.Store(&l) | ||
| } | ||
|
|
||
| // GetLogger returns the global logger. | ||
| func GetLogger() *slog.Logger { | ||
| return globalLogger.Load() | ||
| } | ||
|
|
||
| // Infof logs informational messages about the general state of the profiler. | ||
| // This function is a wrapper around the structured slog-based logger, | ||
| // formatting the message as a string for backward compatibility with | ||
| // previous unstructured logging. | ||
| func Infof(msg string, keysAndValues ...any) { | ||
| GetLogger().Info(fmt.Sprintf(msg, keysAndValues...)) | ||
rogercoll marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| // Info logs informational messages about the general state of the profiler. | ||
| // This is a wrapper around Infof for convenience. | ||
| func Info(msg string) { | ||
| GetLogger().Info(msg) | ||
| } | ||
|
|
||
| // Errorf logs error messages about exceptional states of the profiler. | ||
| // This wrapper formats structured log data into a string message for | ||
| // backward compatibility with older unstructured logs. | ||
| func Errorf(msg string, keysAndValues ...any) { | ||
| GetLogger().Error(fmt.Sprintf(msg, keysAndValues...)) | ||
| } | ||
|
|
||
| // Error logs error messages about exceptional states of the profiler. | ||
| // This is a wrapper around Errorf for convenience. | ||
| func Error(msg error) { | ||
| GetLogger().Error(msg.Error()) | ||
| } | ||
|
|
||
| // Debugf logs detailed debugging information about internal profiler behavior. | ||
| // This wrapper converts structured log data into a string message for | ||
| // backward compatibility with older unstructured logs. | ||
| func Debugf(msg string, keysAndValues ...any) { | ||
| GetLogger().Debug(fmt.Sprintf(msg, keysAndValues...)) | ||
| } | ||
|
|
||
| // Debug logs detailed debugging information about internal profiler behavior. | ||
| // This is a wrapper around Debugf for convenience. | ||
| func Debug(msg string) { | ||
| GetLogger().Debug(msg) | ||
| } | ||
|
|
||
| // Warnf logs warnings in the profiler — not errors, but likely more important | ||
| // than informational messages. This wrapper preserves backward compatibility | ||
| // by string-formatting structured log data. | ||
| func Warnf(msg string, keysAndValues ...any) { | ||
| GetLogger().Warn(fmt.Sprintf(msg, keysAndValues...)) | ||
| } | ||
|
|
||
| // Warn logs warnings in the profiler — not errors, but likely more important | ||
| // than informational messages. This is a wrapper around Warnf for convenience. | ||
| func Warn(msg string) { | ||
| GetLogger().Warn(msg) | ||
| } | ||
|
|
||
| // Fatalf logs a fatal error message and exits the program. | ||
| // This wrapper maintains backward compatibility with unstructured logs by | ||
| // formatting messages as strings. | ||
| // TODO: remove Fatalf calls from the codebase (https://github.com/open-telemetry/opentelemetry-ebpf-profiler/issues/888). | ||
| func Fatalf(msg string, keysAndValues ...any) { | ||
| Errorf(msg, keysAndValues...) | ||
| os.Exit(1) | ||
| } | ||
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
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
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
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
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
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
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
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
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
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
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
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
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.
Uh oh!
There was an error while loading. Please reload this page.