Logging
Save agent activity to files with the log parameter.
Quick Start
Enable Logging
The simplest way to keep a record of your agent's activity.
agent = Agent("assistant", log=True).co/logs/assistant.logLogging Modes
| Mode | Code | File Location | Use Case |
|---|---|---|---|
| Default | log=False | None | Testing, quick scripts |
| Standard | log=True | .co/logs/<name>.log | Production, audit trails |
| Custom | log="file.log" | ./file.log | Debugging, specific output |
Log Format
Logs include timestamps, user input, LLM calls, tool executions, and results:
[2025-09-25 10:32:14.123] INPUT: Generate a Python function
[2025-09-25 10:32:14.127] LLM_REQUEST: model=gpt-4 messages=2
[2025-09-25 10:32:15.235] LLM_RESPONSE: duration=1.1s
[2025-09-25 10:32:15.238] TOOL_CALL: generate_code(language="python")
[2025-09-25 10:32:15.286] TOOL_RESULT: success (0.05s)
[2025-09-25 10:32:16.458] RESULT: Task completed
[2025-09-25 10:32:16.461] DURATION: 2.3sWhat's Logged
- •User input
- •LLM requests with timing
- •Tool calls and results
- •Final responses
- •Total execution time
Benefits
- ✓Audit trail for compliance
- ✓Debug agent behavior
- ✓Performance monitoring
- ✓Error tracking
View Logs
Watch in real-time
Search for errors
See all tool calls
Environment Variable
Set log file via environment variable:
Priority order: Environment variable → log parameter → default (no logging)
Auto Rotation
Logs automatically rotate when they exceed 10MB:
assistant.log # Current
assistant_20250925.log # RotatedHow It Works
- 1.Log file reaches 10MB
- 2.Renamed with date suffix
- 3.New log file created
- 4.Continues logging
Why 10MB?
- ✓Small enough to open quickly
- ✓Large enough for daily use
- ✓Prevents disk space issues
Git Ignore
Security Warning
Log files often contain sensitive information like API keys, user data, or internal logic. Never commit them to version control.
Add to your .gitignore:
*.log
.co/logs/Default Location
When using log=True, logs are saved to:
This provides automatic audit trails for all your agents in one organized location.
Complete Example
Full logging setup with multiple agents:
from connectonion import Agent
# Development: detailed logging
dev_agent = Agent(
"dev_assistant",
log="dev.log",
debug=True # Console + file logging
)
# Production: file logging only
prod_agent = Agent(
"prod_assistant",
log=True, # Logs to .co/logs/prod_assistant.log
debug=False # No console output
)
# Test: no logging
test_agent = Agent(
"test_assistant"
# No log parameter = no logging
)
# Using environment variable
import os
os.environ['CONNECTONION_LOG'] = 'all_agents.log'
env_agent = Agent("env_assistant") # Uses all_agents.logBest Practices
- •Use
log=Truein production for audit trails - •Use custom log files for specific debugging
- •Disable logging in tests to avoid clutter
- •Add
*.logto.gitignore - •Use environment variables for deployment flexibility
Philosophy
Use log=True when you need persistent records.
That's it. Simple, automatic, and always there when you need it.
