Skip to content

feat: configurable logging level with env variable#216

Merged
SantiagoDePolonia merged 2 commits into
mainfrom
feat/customizable-logging-level
Apr 8, 2026
Merged

feat: configurable logging level with env variable#216
SantiagoDePolonia merged 2 commits into
mainfrom
feat/customizable-logging-level

Conversation

@SantiagoDePolonia
Copy link
Copy Markdown
Contributor

@SantiagoDePolonia SantiagoDePolonia commented Apr 8, 2026

Summary by CodeRabbit

  • New Features

    • Added configurable logging verbosity via LOG_LEVEL (debug, info (default), warn, error).
  • Documentation

    • Updated env template and guides to document LOG_LEVEL, clarify LOG_FORMAT auto-detection, and show examples.
  • Tests

    • Added tests covering log-level parsing and handler behavior.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 8, 2026

📝 Walkthrough

Walkthrough

Adds a dedicated logging initializer exposing LOG_LEVEL, moves logging setup out of main into configureLogging, updates docs to document LOG_LEVEL and LOG_FORMAT, and removes godotenv.Load() from config.Load() so .env is loaded earlier by the entrypoint.

Changes

Cohort / File(s) Summary
Configuration & Documentation
/.env.template, DEVELOPMENT.md, GETTING_STARTED.md
Introduce LOG_LEVEL documentation and examples (supported values: debug, info, warn, error plus aliases). Clarify LOG_FORMAT auto-detection and update example commands and env reference tables.
Logging Implementation
cmd/gomodel/logging.go
New logging module: configureLogging(w, isTTY) reads LOG_LEVEL, parses it via parseLogLevel, and installs a process-wide slog logger using a TTY-aware text handler (via tint) or JSON handler. Includes newLogHandler logic for format/TTY selection and time format configuration.
Logging Tests
cmd/gomodel/logging_test.go
New tests for parseLogLevel (accepted values/aliases/whitespace), invalid-level error, and handler Enabled behavior for configured minimum levels across TTY/format combinations.
Main & Config Adjustments
cmd/gomodel/main.go, config/config.go
main now calls configureLogging(os.Stderr, term.IsTerminal(...)) and exits on configuration error; removed inline handler construction and related imports. config.Load() no longer calls godotenv.Load(); comment updated to reflect entrypoint .env loading.
Internal Comment Update
internal/httpclient/client.go
Updated comment to note .env is loaded by the application entrypoint before config/providers initialize.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Poem

🐇 I sniffed the env for levels bright,

debug to error, colors or byte,
A little hop, configure, set—
Logs line up, no worries yet. ✨

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 14.29% 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 pull request title accurately summarizes the main feature: adding a configurable logging level via an environment variable, which is the primary change across the codebase.

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

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/customizable-logging-level

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.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@cmd/gomodel/logging_test.go`:
- Line 31: Remove the redundant per-iteration capture statements "tt := tt" in
the test code (they are unnecessary since Go 1.22+ scopes range variables per
iteration); locate the two occurrences of the exact statement and delete them
(no other changes needed), ensuring the range loop body still references the
loop variable "tt" directly.

In `@cmd/gomodel/logging.go`:
- Around line 20-30: The duplicate godotenv.Load() call should be centralized:
remove the godotenv.Load() invocation from configureLogging and instead call
godotenv.Load() once at program startup (e.g., in main) before invoking
configureLogging and config.Load(); update code so configureLogging(w, isTTY)
only parses env vars and sets up slog without loading dotenv, and ensure main
calls godotenv.Load() once to preserve the intended ordering and avoid future
confusion.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 53493441-021f-443b-8b3e-73a617bd69ac

📥 Commits

Reviewing files that changed from the base of the PR and between c13e278 and 64bf83e.

📒 Files selected for processing (6)
  • .env.template
  • DEVELOPMENT.md
  • GETTING_STARTED.md
  • cmd/gomodel/logging.go
  • cmd/gomodel/logging_test.go
  • cmd/gomodel/main.go

Comment thread cmd/gomodel/logging_test.go Outdated
Comment thread cmd/gomodel/logging.go
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@cmd/gomodel/logging.go`:
- Line 52: Update the invalid-level error message returned (the fmt.Errorf call
that uses envLogLevel and raw) so it lists both canonical log levels and
accepted aliases (e.g., debug/dbg, info/inf, warn/warning, error/err) to avoid
confusion; modify the fmt.Errorf string that currently reads "supported values
are debug, info, warn, error" to include the alias forms alongside the canonical
names while keeping envLogLevel and raw in the formatted message.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 016dfefb-50f8-405b-b033-442d17cb29b0

📥 Commits

Reviewing files that changed from the base of the PR and between 64bf83e and 5ce15d8.

📒 Files selected for processing (5)
  • cmd/gomodel/logging.go
  • cmd/gomodel/logging_test.go
  • cmd/gomodel/main.go
  • config/config.go
  • internal/httpclient/client.go
💤 Files with no reviewable changes (1)
  • config/config.go

Comment thread cmd/gomodel/logging.go
@SantiagoDePolonia SantiagoDePolonia merged commit 40dd779 into main Apr 8, 2026
16 checks passed
@SantiagoDePolonia SantiagoDePolonia deleted the feat/customizable-logging-level branch April 25, 2026 11:57
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