-
Notifications
You must be signed in to change notification settings - Fork 1.6k
⚠️ Migrate from logrus to log/slog #4968
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
⚠️ Migrate from logrus to log/slog #4968
Conversation
|
|
|
Welcome @Shubhamag12! |
|
Hi @Shubhamag12. Thanks for your PR. I'm waiting for a kubernetes-sigs member to verify that this patch is reasonable to test. If it is, they should reply with Once the patch is verified, the new status will be reflected by the I understand the commands that are listed here. Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. |
|
/ok-to-test |
acdabaa to
72f6ac6
Compare
|
/ok-to-test |
b91d466 to
72d3e07
Compare
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.
Pull Request Overview
This PR migrates from the external github.com/sirupsen/logrus logging library to Go's standard library log/slog package. This change eliminates external dependencies and modernizes the logging approach to use structured logging throughout the codebase.
- Replaces all logrus imports with
log/slogimports across the entire codebase - Converts log method calls from logrus format (e.g.,
log.Printf,log.Errorf) to slog structured logging (e.g.,log.Info,log.Errorwith key-value pairs) - Introduces a custom logging handler in
pkg/logging/handler.gowith colored output and structured attribute formatting
Reviewed Changes
Copilot reviewed 49 out of 50 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| pkg/logging/handler.go | New custom slog handler implementation with colored output and structured logging |
| cmd/cmd.go | Updated to use slog and initialize custom logging handler |
| go.mod | Removed logrus dependency |
| Multiple scaffolding files | Converted logrus calls to slog structured logging with key-value pairs |
| Test and utility files | Updated logging imports and method calls to use slog |
| Documentation | Updated example code to reference slog instead of logrus |
| f.PackageName = "controller" | ||
|
|
||
| log.Println("creating import for %", f.Resource.Path) | ||
| log.Info("creating import%", "resource_path", f.Resource.Path) |
Copilot
AI
Aug 3, 2025
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.
The log message contains a malformed format string with '%' at the end. It should be 'creating import for' to be grammatically correct.
| log.Info("creating import%", "resource_path", f.Resource.Path) | |
| log.Info("creating import for", "resource_path", f.Resource.Path) |
| if err != nil { | ||
| if errors.Is(err, afero.ErrFileNotFound) { | ||
| log.Warnf("Unable to find %s : %s .\n"+ | ||
| log.Warn("Unable to find boilerplate file"+ |
Copilot
AI
Aug 3, 2025
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.
Missing space between 'file' and the concatenated string. Should be 'Unable to find boilerplate file. ' with a period and space.
| log.Warn("Unable to find boilerplate file"+ | |
| log.Warn("Unable to find boilerplate file. "+ |
| if err != nil { | ||
| log.Warningf("Unable to find the certificate name replacement for CRD %s "+ | ||
| "to uncomment in %s. Conversion webhooks require this replacement to inject "+ | ||
| log.Warn("Unable to find the certificate name replacement for CRD"+ |
Copilot
AI
Aug 3, 2025
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.
Missing space between 'CRD' and 'to uncomment'. Should be 'Unable to find the certificate name replacement for CRD ' with a space.
| log.Warn("Unable to find the certificate name replacement for CRD"+ | |
| log.Warn("Unable to find the certificate name replacement for CRD "+ |
| log.Warningf("Unable to find the target configurations with kustomizeconfig.yaml"+ | ||
| "to uncomment in the file %s. ConverstionWebhooks requires this configuration "+ | ||
| "to be uncommented to inject CA", kustomizeCRDFilePath) | ||
| log.Warn("Unable to find the target configurations with kustomizeconfig.yaml"+ |
Copilot
AI
Aug 3, 2025
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.
Missing space between 'kustomizeconfig.yaml' and 'to uncomment'. Should be 'Unable to find the target configurations with kustomizeconfig.yaml ' with a space.
| log.Warn("Unable to find the target configurations with kustomizeconfig.yaml"+ | |
| log.Warn("Unable to find the target configurations with kustomizeconfig.yaml "+ |
|
Hi @Shubhamag12 That is great 🎉 I tested locally. |
4491057 to
90ad1ea
Compare
rebase with master
90ad1ea to
5b9ff22
Compare
|
/test pull-kubebuilder-test |
|
/lgtm |
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: camilamacedo86, Shubhamag12 The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
Follow up: kubernetes-sigs#4968 Testing alpha update and generate revealed logs were not in the right format. Changes: - Initialize consistent logging handler in alpha commands to fix level=info msg= format - Replace log.Fatalf with slog.Error + os.Exit(1) for proper error handling - Standardize log imports to use log "log/slog" across all files - Remove redundant command info from RunCmd logging output - Ensure all kubebuilder processes use the same colored INFO/WARN format Before: level=warning msg="Using current working directory..." After: WARN Using current working directory... Assisted-by: Cursor
🌱 (fix): Fix inconsistent logging format ( Follow up: #4968 )
Follow up: kubernetes-sigs#4968 Testing alpha update and generate revealed logs were not in the right format. Changes: - Initialize consistent logging handler in alpha commands to fix level=info msg= format - Replace log.Fatalf with slog.Error + os.Exit(1) for proper error handling - Standardize log imports to use log "log/slog" across all files - Remove redundant command info from RunCmd logging output - Ensure all kubebuilder processes use the same colored INFO/WARN format Before: level=warning msg="Using current working directory..." After: WARN Using current working directory... Assisted-by: Cursor
🐛 (fix) reformat subprocess output for consistent logging during alpha commands (Follow up: #4968)
We want to migrate from the external github.com/sirupsen/logrus dependency to Go's standard library log/slog package. This will eliminate external dependencies and improve performance.
Fixes: #4930