Skip to content

Set IG logger level based on global log level#715

Merged
matthyx merged 1 commit intomainfrom
ig-logger
Feb 10, 2026
Merged

Set IG logger level based on global log level#715
matthyx merged 1 commit intomainfrom
ig-logger

Conversation

@matthyx
Copy link
Contributor

@matthyx matthyx commented Feb 10, 2026

Summary by CodeRabbit

  • Chores
    • Enhanced runtime logging so the component’s log level now follows the global setting (debug vs. error).
    • Minor formatting and whitespace cleanups with no functional impact.

Copy link

Copilot AI left a 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 adjusts Inspektor Gadget’s internal logger verbosity to follow the node-agent’s global log level at startup.

Changes:

  • Add Inspektor Gadget logger import.
  • Set Inspektor Gadget default logger level during main() initialization based on kubescape/go-logger level.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 20 to 22
igconfig "github.com/inspektor-gadget/inspektor-gadget/pkg/config"
iglogger "github.com/inspektor-gadget/inspektor-gadget/pkg/logger"
containercollection "github.com/inspektor-gadget/inspektor-gadget/pkg/container-collection"
Copy link

Copilot AI Feb 10, 2026

Choose a reason for hiding this comment

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

Import block is no longer gofmt-sorted after adding iglogger (the inspektor-gadget imports should be ordered lexicographically). Please run gofmt or reorder imports to avoid inconsistent formatting across the repo.

Suggested change
igconfig "github.com/inspektor-gadget/inspektor-gadget/pkg/config"
iglogger "github.com/inspektor-gadget/inspektor-gadget/pkg/logger"
containercollection "github.com/inspektor-gadget/inspektor-gadget/pkg/container-collection"
containercollection "github.com/inspektor-gadget/inspektor-gadget/pkg/container-collection"
igconfig "github.com/inspektor-gadget/inspektor-gadget/pkg/config"
iglogger "github.com/inspektor-gadget/inspektor-gadget/pkg/logger"

Copilot uses AI. Check for mistakes.
Comment on lines +369 to +373
if logger.L().GetLevel() == "debug" {
iglogger.DefaultLogger().SetLevel(iglogger.DebugLevel)
} else {
iglogger.DefaultLogger().SetLevel(iglogger.ErrorLevel)
}
Copy link

Copilot AI Feb 10, 2026

Choose a reason for hiding this comment

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

This sets Inspektor Gadget logging to Debug only when the global logger is exactly "debug", and to Error for all other levels. That behavior is not really "based on global log level" (e.g., if the app runs at info/warn, IG warnings/info will be suppressed). Consider mapping the global level to the closest IG level (debug/info/warn/error) or otherwise documenting why IG should be forced to Error in non-debug mode.

Copilot uses AI. Check for mistakes.
@coderabbitai
Copy link

coderabbitai bot commented Feb 10, 2026

📝 Walkthrough

Walkthrough

Introduced an import alias for the IG logger and a runtime log level switch: when the global logger level is "debug" set the IG logger to DebugLevel, otherwise set it to ErrorLevel. Minor formatting spacing tweaks were also made.

Changes

Cohort / File(s) Summary
Logger Configuration
cmd/main.go
Added iglogger import alias and conditional runtime log level setup for the IG logger (DebugLevel when global logger is debug, otherwise ErrorLevel). Minor non-functional formatting adjustments.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Poem

I nibble through the logging vine,
Toggling levels, neat and fine,
Debug for curious midnight hops,
Error for when the tumble stops,
— a rabbit’s patch of logging shine 🐇✨

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: configuring the IG logger level based on the global log level configuration, which is the primary purpose of this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch ig-logger

No actionable comments were generated in the recent review. 🎉


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Signed-off-by: Matthias Bertschy <matthias.bertschy@gmail.com>
@matthyx matthyx merged commit a0c473e into main Feb 10, 2026
27 checks passed
@matthyx matthyx deleted the ig-logger branch February 10, 2026 20:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant