Documentation Index
Fetch the complete documentation index at: https://mintlify.com/Menelaus29/c2-framework/llms.txt
Use this file to discover all available pages before exploring further.
Overview
The logger module provides structured JSON logging with automatic file rotation and session-based tracking. All logs are output in JSON format with consistent fields for easy parsing and analysis. File:common/logger.py
Features
JSON Format
Every log line is valid JSON for easy machine parsing
File Rotation
Automatic log rotation based on size with configurable backup count
Session Tracking
Associate logs with specific agent sessions
Dual Output
Logs written to both stdout and rotating files
Functions
get_logger()
Get or create a JSON logger for a component with optional session tracking.Component name (e.g., ‘agent’, ‘server’, ‘transport’). Used as log filename and in structured output.
Optional session identifier to track logs for specific agent sessions
Configured logger instance with JSON formatting and rotation
- Log level from
config.LOG_LEVEL(default: INFO) - Dual handlers: stdout + rotating file
- File location:
{config.LOG_DIR}/{component}.log - Rotation:
config.LOG_MAX_BYTESper file,config.LOG_BACKUP_COUNTbackups - Caching: Loggers are cached by
component:session_idkey
update_session()
Create a new logger for the same component with an updated session ID.Existing logger instance
New session identifier
New logger instance for the same component with updated session ID
- Agent receives session ID after check-in
- Update logger to include session ID in all subsequent logs
Log Format
Each log entry is a JSON object with the following structure:Standard Fields
ISO 8601 timestamp in UTC+7 timezone with microsecond precision
Log level:
DEBUG, INFO, WARNING, ERROR, or CRITICALComponent name specified in
get_logger()Session identifier if provided, otherwise
nullLog message text
Extra Fields
Any additional fields passed via theextra kwarg are automatically included:
Exception Logging
When logging exceptions, traceback is automatically included:Configuration
Logger behavior is controlled bycommon/config.py:
Log Levels
| Level | Use Case |
|---|---|
DEBUG | Detailed diagnostic information for development |
INFO | General informational messages about normal operation |
WARNING | Warning messages for potentially problematic situations |
ERROR | Error messages for serious problems |
CRITICAL | Critical messages for very serious errors |
File Organization
Logs are organized by component:Caching Behavior
Loggers are cached internally to prevent duplicate handlers:- Cache key:
{component}:{session_id} - First call creates logger with handlers
- Subsequent calls return cached instance
- Each unique
component:session_idpair gets its own logger
Usage Examples
Basic Logging
Session-Based Logging
Structured Logging with Extra Fields
Error Handling
Implementation Details
Timezone
Logs use UTC+7 timezone:Reserved Keys
The following keys are reserved and excluded from extra fields:Formatter Implementation
Best Practices
Use Structured Logging
Use Structured Logging
Always pass structured data as
extra fields instead of string formatting:Include Session IDs
Include Session IDs
Always use session-aware loggers for agent operations:
Log Exceptions Properly
Log Exceptions Properly
Use
exc_info=True to include tracebacks:Choose Appropriate Log Levels
Choose Appropriate Log Levels
DEBUG: Detailed info for troubleshootingINFO: Normal operations and state changesWARNING: Degraded operation or potential issuesERROR: Operation failures that need attentionCRITICAL: System-level failures
Dependencies
See Also
- Configuration - Logging configuration variables
- Common Utilities - Error classes logged by this module