ConnectOnionConnectOnion

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.

Recommended for Production
agent = Agent("assistant", log=True)
Saves to: .co/logs/assistant.log

Logging Modes

ModeCodeFile LocationUse Case
Defaultlog=FalseNoneTesting, quick scripts
Standardlog=True.co/logs/<name>.logProduction, audit trails
Customlog="file.log"./file.logDebugging, 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.3s

What'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

Terminal
$tail -f assistant.log

Search for errors

Terminal
$grep ERROR assistant.log

See all tool calls

Terminal
$grep TOOL assistant.log

Environment Variable

Set log file via environment variable:

Terminal
$CONNECTONION_LOG=debug.log python agent.py

Priority order: Environment variable → log parameter → default (no logging)

Auto Rotation

Logs automatically rotate when they exceed 10MB:

assistant.log           # Current
assistant_20250925.log  # Rotated

How 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:

.co/logs/{'agent_name'}.log

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.log

Best Practices

  • Use log=True in production for audit trails
  • Use custom log files for specific debugging
  • Disable logging in tests to avoid clutter
  • Add *.log to .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.