Skip to content

feat(logging): add configurability for log levels preference#1853

Merged
yinwm merged 8 commits intosipeed:mainfrom
kunalk16:feat-configurable-logger
Mar 22, 2026
Merged

feat(logging): add configurability for log levels preference#1853
yinwm merged 8 commits intosipeed:mainfrom
kunalk16:feat-configurable-logger

Conversation

@kunalk16
Copy link
Copy Markdown
Contributor

📝 Description

As of now, in the latest release, when we perform commands such as "picoclaw agent", it defaults to log level info and if we use the --debug parameter with the "picoclaw agent" command, it overrides to log level debug. Users may or may not be needing the logging and hence, this PR is adding configurability to the logging.

🗣️ Type of Change

  • 🐞 Bug fix (non-breaking change which fixes an issue)
  • ✨ New feature (non-breaking change which adds functionality)
  • 📖 Documentation update
  • ⚡ Code refactoring (no functional changes, no api changes)

🤖 AI Code Generation

  • 🤖 Fully AI-generated (100% AI, 0% Human)
  • 🛠️ Mostly AI-generated (AI draft, Human verified/modified)
  • 👨‍💻 Mostly Human-written (Human lead, AI assisted or none)

🔗 Related Issue

Closes #1848

📚 Technical Context (Skip for Docs)

  • Reference URL:
  • Reasoning:

🧪 Test Environment

  • Hardware: Dell Laptop(test was executed in a container)
  • OS: Ubuntu 25.10(container)
  • Model/Provider: Azure OpenaAI GPT 5.3 Chat
  • Channels: N/A

📸 Evidence (Optional)

Click to view Logs/Screenshots **Before the change** **log level INFO by default** default-without-config

After the change
Default config after onboarding
default-config-post-onboarding

Config updated to log level fatal
config-updated-to-fatal

Config updated to log level error
config-updated-to-error

Config updated to log level debug
config-updated-to-debug

Config updated to log level with invalid value falls back to info
config-updated-to-incorrect-value-fallback-to-info

Config overridden to log level debug when --debug parameter is used
config-overridden-by-debug-parameter

☑️ Checklist

  • My code/docs follow the style of this project.
  • I have performed a self-review of my own changes.
  • I have updated the documentation accordingly.

@sipeed-bot sipeed-bot bot added type: enhancement New feature or request domain: config go Pull requests that update go code labels Mar 21, 2026
@liuy
Copy link
Copy Markdown
Contributor

liuy commented Mar 21, 2026

#1828 is a lighter approach,no need add complexity I would suggest it

@kunalk16
Copy link
Copy Markdown
Contributor Author

#1828 is a lighter approach,no need add complexity I would suggest it

Disagree, my approach is like any other enterprise grade application where we are having control over log levels through the config file. Not sure why it is being considered "complex"

Copy link
Copy Markdown
Collaborator

@yinwm yinwm left a comment

Choose a reason for hiding this comment

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

LGTM. Reviewed: default log level choice is intentional, tests are comprehensive, debug flag correctly overrides config.

@yinwm yinwm merged commit 931eee9 into sipeed:main Mar 22, 2026
4 checks passed
@yinwm
Copy link
Copy Markdown
Collaborator

yinwm commented Mar 22, 2026

Related PR: #1828

This PR has a dependency relationship with #1828 (feat(logger): add PICOCLAW_LOG_FILE env var for file-only logging).

Why This PR Should Be Merged First

This PR (#1853) should be merged before #1828.

Reasons:

  1. Initialization Order: This PR changes the initialization sequence - it moves LoadConfig() before the debug flag check, and calls SetLevelFromString() inside LoadConfig(). This establishes the correct order: config → log level → debug override.

  2. No Breaking Changes: This PR is self-contained and doesn't depend on feat(logger): add PICOCLAW_LOG_FILE env var for file-only logging #1828's changes.

  3. Rebase Simplicity: feat(logger): add PICOCLAW_LOG_FILE env var for file-only logging #1828 only adds one line (logger.ConfigureFromEnv()) to agent/helpers.go. Rebasing feat(logger): add PICOCLAW_LOG_FILE env var for file-only logging #1828 onto this PR is straightforward.

  4. Logical Priority: Log level configuration (this PR) is more fundamental than log destination configuration (feat(logger): add PICOCLAW_LOG_FILE env var for file-only logging #1828). Setting the level first makes semantic sense.

Conflict Files

File This PR #1828
cmd/picoclaw/internal/agent/helpers.go Moves debug/LoadConfig order Adds ConfigureFromEnv() call
pkg/logger/logger.go Adds ParseLevel, SetLevelFromString Adds DisableConsole, ConfigureFromEnv
pkg/logger/logger_test.go Adds tests Adds tests

After Merge: Action for #1828

Once this PR is merged, #1828 should:

  1. Rebase onto updated main

  2. Place logger.ConfigureFromEnv() after LoadConfig() call

  3. Ensure the final order is:
    ```go
    // 1. Load config (sets log level)
    cfg, err := internal.LoadConfig()

    // 2. Apply env var overrides (feat(logger): add PICOCLAW_LOG_FILE env var for file-only logging #1828)
    logger.ConfigureFromEnv()

    // 3. Debug flag has highest priority
    if debug {
    logger.SetLevel(logger.DEBUG)
    }
    ```

Feature Relationship

This PR (#1853) #1828
Controls log level (what) Controls log destination (where)
log_level: "debug" in config PICOCLAW_LOG_FILE=/tmp/agent.log
Config file + env var Env var only

Both features work together:
```bash

Set log level via config, log destination via env

PICOCLAW_LOG_FILE=/var/log/picoclaw.log picoclaw agent

(config.json has "log_level": "debug")

```


Recommendation: ✅ This PR is ready to merge. Please approve and merge before #1828.

@huaaudio
Copy link
Copy Markdown
Collaborator

huaaudio commented Mar 22, 2026

Hi @kunalk16 , thanks for the pr! I noticed the log change from the current main branch. However, for the config, it is a bit improper here to put log_level inside "agents", as it is not the log of the agent. Maybe consider changing it under "gateway" or somewhere could make more sense? Also, it would be really good to document the change. Thanks in advance for your help!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

domain: config go Pull requests that update go code type: enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature] Allow more control over logging through config

4 participants