set the log level from the config file
I use openhue-cli inside a script for polybar and I have lots of accessories that are not lights so the log is growing to much.
With this simple change, the user can choose the log level he want from the config file Log levels are strings from Logrus
Summary by CodeRabbit
-
New Features
- Added configurable log level support β the app now reads and applies a user-specified logging verbosity at startup.
-
Bug Fixes
- Logging now respects the configured level instead of using a fixed default; invalid log level values will cause startup to fail so issues are surfaced immediately.
Walkthrough
Config gains a new LogLevel field and the logger Init function now accepts and applies a log level from configuration; logger initialization reads and parses that level and sets the logger accordingly, fatalling on parse error.
Changes
| Cohort / File(s) | Summary |
|---|---|
Configuration & Logger openhue/config.go, util/logger/logger.go |
Added LogLevel string to Config; changed Init(path string) β Init(path string, level string); logger now parses level with log.ParseLevel and sets log.SetLevel(logLevel); parse errors call log.Fatal(err). |
Sequence Diagram
sequenceDiagram
participant Config
participant Logger as Logger.Init
participant LogLib as log package
Config->>Config: load config file
Config->>Config: read `LogLevel`
Config->>Logger: Init(path, LogLevel)
alt parse succeeds
Logger->>LogLib: ParseLevel(level)
Logger->>LogLib: SetLevel(parsedLevel)
Logger->>LogLib: SetOutput(file)
else parse fails
Logger->>Logger: Fatal(error)
end
Estimated code review effort
π― 3 (Moderate) | β±οΈ ~20 minutes
- Check callers of
util/logger.Initfor updated signature usage. - Confirm fatal-on-parse behavior is intentional (unreachable assignment after
log.Fatal). - Verify tests or startup paths handle missing/invalid
LogLevelvalues and that defaulting behavior (if desired) is handled elsewhere.
Poem
π In burrows of code I hop and peep,
I tweak the logs so wakes not sleep.
A level added, crisp and bright,
Now bunnies whisper or roar by night. π₯
Pre-merge checks and finishing touches
β 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%. | You can run @coderabbitai generate docstrings to improve docstring coverage. |
β 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 clearly and concisely summarizes the main change: allowing users to set the log level from the configuration file, which is the primary objective of the PR. |
β¨ Finishing touches
- [ ] π Generate docstrings
π§ͺ Generate unit tests (beta)
- [ ] Create PR with unit tests
- [ ] Post copyable unit tests in a comment
π Recent review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
π₯ Commits
Reviewing files that changed from the base of the PR and between 6f76573bd0b8178a6ed1dfaa9807b6aaad10c642 and f058751852ececb24180aeea365d5189e49f8c4c.
π Files selected for processing (1)
-
util/logger/logger.go(1 hunks)
π Additional comments (1)
util/logger/logger.go (1)
8-8: Function signature updated to accept log level parameter.The addition of the
levelparameter enables configurable log levels from the configuration file, which aligns well with the PR objectives.
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.
Comment @coderabbitai help to get the list of available commands and usage tips.