Skip to content

Add --log-level flag with log/slog structured logging#60

Merged
openshift-merge-bot[bot] merged 1 commit into
openshift:mainfrom
sebrandon1:add-log-level-flags
May 13, 2026
Merged

Add --log-level flag with log/slog structured logging#60
openshift-merge-bot[bot] merged 1 commit into
openshift:mainfrom
sebrandon1:add-log-level-flags

Conversation

@sebrandon1
Copy link
Copy Markdown
Member

@sebrandon1 sebrandon1 commented May 11, 2026

Summary

  • Migrates all log.Printf calls to Go's stdlib log/slog with structured key-value pairs
  • Adds --log-level flag accepting debug, info, warn, error (default: info)
  • Debug level enables verbose output including per-pod discovery detail, lsof output, and component analysis
  • Warn level suppresses informational messages
  • All log messages use idiomatic slog structured args for efficient filtering and machine-parseable output
  • Replaces panic with error return in Policy() for graceful handling of policy parse failures (supersedes Replace panic with error return in Policy() #52)
  • No new dependencies — log/slog is Go stdlib

Jira: https://redhat.atlassian.net/browse/CNF-23702

@openshift-ci openshift-ci Bot requested review from rhmdnd and smith-xyz May 11, 2026 16:07
Copy link
Copy Markdown
Contributor

@smith-xyz smith-xyz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

great addition! I do think this is a reasonable add but I'd request the following:

Consider using log/slog instead of a custom logging package. It gives you leveled logging, slog.SetDefault() for global config, and a single --log-level flag covers all cases without needing mutually exclusive --debug/--quiet. Less code to maintain and a standard interface other contributors already know.

@sebrandon1
Copy link
Copy Markdown
Member Author

Good idea, I can switch to slog. Let me play with that.

@sebrandon1 sebrandon1 force-pushed the add-log-level-flags branch from d8eb68e to 43514a2 Compare May 11, 2026 18:34
@sebrandon1 sebrandon1 changed the title Add --debug/--quiet flags for log level control Add --log-level flag with log/slog structured logging May 11, 2026
Migrate all log.Printf calls to Go's stdlib log/slog with structured
key-value pairs. Replaces the standard log package with slog's leveled
logging throughout the codebase.

- --log-level flag accepts debug, info, warn, error (default: info)
- Debug level enables verbose output including per-pod discovery
  detail, lsof output, and component analysis
- Warn level suppresses informational messages
- All log messages use idiomatic slog structured args for efficient
  filtering and machine-parseable output
- Replace panic with error return in Policy() for graceful handling
  of policy parse failures
@sebrandon1
Copy link
Copy Markdown
Member Author

I closed #52 and cherry-picked the changes into this one as they were similar.

@openshift-ci
Copy link
Copy Markdown

openshift-ci Bot commented May 11, 2026

@sebrandon1: all tests passed!

Full PR test history. Your PR dashboard.

Details

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. I understand the commands that are listed here.

@openshift-ci openshift-ci Bot added lgtm Indicates that a PR is ready to be merged. approved Indicates a PR has been approved by an approver from all required OWNERS files. labels May 13, 2026
@smith-xyz
Copy link
Copy Markdown
Contributor

/lgtm
/approve

thank you again @sebrandon1 for your contribution

@openshift-ci
Copy link
Copy Markdown

openshift-ci Bot commented May 13, 2026

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: sebrandon1, smith-xyz

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@openshift-merge-bot openshift-merge-bot Bot merged commit 3c93aa3 into openshift:main May 13, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved Indicates a PR has been approved by an approver from all required OWNERS files. lgtm Indicates that a PR is ready to be merged.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants