Skip to content

feat(logger): add PICOCLAW_LOG_FILE env var for file-only logging#1828

Open
liuy wants to merge 1 commit intosipeed:mainfrom
liuy:feat/logging-config
Open

feat(logger): add PICOCLAW_LOG_FILE env var for file-only logging#1828
liuy wants to merge 1 commit intosipeed:mainfrom
liuy:feat/logging-config

Conversation

@liuy
Copy link
Contributor

@liuy liuy commented Mar 20, 2026

Summary

Add file-only logging support for picoclaw agent via PICOCLAW_LOG_FILE environment variable.

Motivation

Currently picoclaw agent outputs all logs to stdout/console, which can interfere with interactive use cases (e.g., TUI scenarios). Users need a way to redirect logs to a file only.

Usage

PICOCLAW_LOG_FILE=/tmp/agent.log picoclaw agent
PICOCLAW_LOG_FILE=~/.picoclaw/logs/agent.log picoclaw agent

@sipeed-bot sipeed-bot bot added type: enhancement New feature or request domain: agent go Pull requests that update go code labels Mar 20, 2026
@yinwm
Copy link
Collaborator

yinwm commented Mar 22, 2026

Related PR: #1853

This PR has a dependency relationship with #1853 (feat(logging): add configurability for log levels preference).

Conflict Analysis

Both PRs modify cmd/picoclaw/internal/agent/helpers.go:

This PR (#1828) #1853
Adds logger.ConfigureFromEnv() at function start Moves debug flag handling after LoadConfig()
Modifies pkg/logger/logger.go (adds DisableConsole, ConfigureFromEnv) Modifies pkg/logger/logger.go (adds ParseLevel, SetLevelFromString)

Recommended Merge Order

#1853 should be merged first, then this PR needs to be rebased.

Reason:

Suggested Integration (after #1853 is merged)

```go
func agentCmd(...) error {
// 1. Load config first (sets log level via SetLevelFromString internally)
cfg, err := internal.LoadConfig()

// 2. Apply env var overrides (file logging can override config)
logger.ConfigureFromEnv()  // ← This PR

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

}
```

Feature Summary

These two features are complementary and work together:
```bash
PICOCLAW_LOG_FILE=/tmp/agent.log picoclaw agent # This PR: logs go to file

config.json: {"log_level": "debug"} # #1853: logs at debug level

```

@yinwm
Copy link
Collaborator

yinwm commented Mar 22, 2026

@liuy plz resolve conflicts.

- Add PICOCLAW_LOG_FILE environment variable for configuring log file path
- Add ConfigureFromEnv() function to read log config from environment
- Add DisableConsole() to suppress console output
- Add TestDisableConsole, TestConfigureFromEnv, TestConfigureFromEnvNoEnv tests
- Merge main branch tests: TestDefaultLevelIsInfo, TestParseLevelValid, TestParseLevelInvalid, TestSetLevelFromString
- Reorder: LoadConfig before ConfigureFromEnv per PR review
@liuy liuy force-pushed the feat/logging-config branch from 18d9f0b to 553bece Compare March 22, 2026 06:34
@liuy
Copy link
Contributor Author

liuy commented Mar 22, 2026

@liuy plz resolve conflicts.

Done as commented

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

Labels

domain: agent 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.

2 participants