# 📊 Ollama_Agents Logging System Documentation
## 1. 🚀 Introduction
The Ollama_Agents project implements a comprehensive logging system to enhance debugging, monitoring, and maintenance capabilities. This document outlines the logging strategy, implementation details, and best practices for using and maintaining the logging system.
## 2. 🎯 Logging Strategy
### 2.1 🎨 Objectives
- 👁️ Provide visibility into application flow and behavior
- 🐛 Facilitate debugging and error tracking
- 📈 Monitor performance and resource usage
- 📜 Support auditing and compliance requirements
### 2.2 🔍 Log Levels
The project uses Python's built-in logging module with the following log levels:
1. 🔬 DEBUG: Detailed information, typically of interest only when diagnosing problems.
2. ℹ️ INFO: Confirmation that things are working as expected.
3. ⚠️ WARNING: An indication that something unexpected happened, or indicative of some problem in the near future.
4. ❌ ERROR: Due to a more serious problem, the software has not been able to perform some function.
5. 🚨 CRITICAL: A serious error, indicating that the program itself may be unable to continue running.
## 3. 🛠️ Implementation Details
### 3.1 🔧 Logging Setup
The logging configuration is centralized in the `src/modules/logging_setup.py` file:
```python
import logging
from config import LOG_LEVEL, LOG_FILE
def setup_logging():
logger = logging.getLogger("ollama_agents")
logger.setLevel(LOG_LEVEL)
file_handler = logging.FileHandler(LOG_FILE, mode='a', encoding='utf-8')
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
file_handler.setFormatter(formatter)
logger.addHandler(file_handler)
logger.propagate = False
return logger
logger = setup_logging()
Each module imports and uses the logger as follows:
from src.modules.logging_setup import logger
def some_function():
logger.info("Function started")
# ... function logic ...
logger.debug("Operation completed")
- 🚪 Function entry and exit
- 🧠 Important operations or decisions
- 🚫 Error conditions and exceptions
- ⏱️ Performance-sensitive operations
- 📝 Logs the assembly of prompts with history
- 🔢 Tracks the number of history entries and chunk sizes
- 📥 Logs file read/write operations
- 📁 Tracks directory creation and file listing
- ➕ Logs chunk addition, retrieval, and assembly
- 💾 Tracks saving and loading of chunk history
- 🖼️ Logs the creation and display of visual elements
- 👤 Tracks user-specific banner generation
- 🌐 Logs API requests and responses
- ⏲️ Tracks processing times for Ollama interactions
- 🎯 Be concise and descriptive
- 🔢 Include relevant variable values
- 🔤 Use consistent terminology
Example:
logger.info(f"Processing file: {filename}")
- 🚫 Never log sensitive data (passwords, API keys, etc.)
- ✂️ Truncate long strings to prevent log bloat
Example:
logger.debug(f"User input: {user_input[:50]}...") # Log only first 50 characters
- 😴 Use lazy logging for expensive operations
- 🏎️ Be mindful of logging in tight loops
Example:
if logger.isEnabledFor(logging.DEBUG):
logger.debug(f"Expensive operation result: {calculate_expensive_result()}")
- 📜 Always log exceptions with tracebacks
- 🖼️ Provide context for errors
Example:
try:
# ... some operation ...
except Exception as e:
logger.exception(f"Error processing {item}: {str(e)}")
Implement log rotation to manage log file sizes:
from logging.handlers import RotatingFileHandler
file_handler = RotatingFileHandler(LOG_FILE, maxBytes=10*1024*1024, backupCount=5)
Regularly review logs for:
- 🐞 Error patterns
- 🐢 Performance bottlenecks
- 🕵️ Unusual activity
Consider using log analysis tools for large-scale systems.
- 🧱 Implement structured logging (e.g., JSON format) for easier parsing
- 🌐 Integrate with a centralized logging system for distributed deployments
- 🚨 Add real-time log monitoring and alerting
The logging system in Ollama_Agents provides comprehensive visibility into the application's behavior. By following these guidelines and best practices, developers can maintain an effective logging strategy that supports debugging, monitoring, and overall system health.