Skip to content

Commit dff2e96

Browse files
committed
Ensure file logs always capture DEBUG and document file logging/rotation
- Set root logger to DEBUG when file logging is enabled so log files record full details - Clarify console vs file logging in README - Document BRAIN_LOG_FILE behavior: automatic rotation (10MB per file, 5 backups), always captures DEBUG, and provide example path
1 parent ede401f commit dff2e96

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

README.md

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,9 @@ brain --verbose <command> # Show key operations
132132
brain --debug <command> # Full diagnostics with LLM details
133133
```
134134

135-
> **Logs:** By default, logs are suppressed during operations to avoid interrupting spinners. Use `--verbose` or `--debug` for detailed information with beautiful Rich formatting.
135+
> **Console Logs:** By default, logs are suppressed during operations to avoid interrupting spinners. Use `--verbose` or `--debug` for detailed information with beautiful Rich formatting.
136+
137+
> **File Logs:** Optional. Set `BRAIN_LOG_FILE` in `.env` to enable persistent logging with automatic rotation (max 10MB per file, 5 backups). File logs always capture full DEBUG details regardless of console log level.
136138
137139
> **Cost Tracking:** All Azure OpenAI usage is automatically tracked in a local SQLite database (`~/.brain/costs.db`). Data stays private and grows ~10-50 MB/year for typical use.
138140
@@ -160,10 +162,13 @@ Create `~/.config/brain/.env` with these settings:
160162
- `AZURE_SEARCH_API_KEY` - Azure AI Search API key
161163
- `AZURE_SEARCH_INDEX_NAME` - Search index name (default: second-brain-notes)
162164

163-
**Cost Tracking** (optional configuration):
165+
**Logging & Cost Tracking** (optional configuration):
164166
- `BRAIN_COST_DB_PATH` - Path to cost tracking database (default: ~/.brain/costs.db)
165167
- `BRAIN_LOG_LEVEL` - Logging level: DEBUG, INFO, WARNING, ERROR (default: INFO)
166-
- `BRAIN_LOG_FILE` - Path to log file (optional, logs to console if not set)
168+
- `BRAIN_LOG_FILE` - Path to log file with automatic rotation (optional, logs to console if not set)
169+
- When enabled: captures all DEBUG logs to file regardless of console log level
170+
- Automatic rotation: max 10MB per file, keeps 5 backups (~50MB total)
171+
- Example: `BRAIN_LOG_FILE=~/.brain/logs/brain.log`
167172

168173
**Custom Pricing** (optional - override Azure OpenAI pricing):
169174
- `AZURE_GPT4O_INPUT_PRICE` - Price per 1K input tokens for gpt-4o (default: 0.03)

brain_core/logging_config.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,13 @@ def setup_logging(
5252

5353
# Configure root logger
5454
root_logger = logging.getLogger()
55-
root_logger.setLevel(log_level)
55+
56+
# If file logging is enabled, root logger should capture everything (DEBUG)
57+
# so file gets full details. Console handler will filter based on user preference.
58+
if enable_file_logging:
59+
root_logger.setLevel(logging.DEBUG)
60+
else:
61+
root_logger.setLevel(log_level)
5662

5763
# Clear existing handlers
5864
root_logger.handlers.clear()

0 commit comments

Comments
 (0)