Skip to content

Latest commit

 

History

History
174 lines (118 loc) · 4.87 KB

logging_guide.md

File metadata and controls

174 lines (118 loc) · 4.87 KB
# 📊 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()

3.2 💻 Usage in Modules

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")

3.3 🔑 Key Logging Points

  • 🚪 Function entry and exit
  • 🧠 Important operations or decisions
  • 🚫 Error conditions and exceptions
  • ⏱️ Performance-sensitive operations

4. 📦 Module-Specific Logging

4.1 🧩 assemble.py

  • 📝 Logs the assembly of prompts with history
  • 🔢 Tracks the number of history entries and chunk sizes

4.2 📂 file_utils.py

  • 📥 Logs file read/write operations
  • 📁 Tracks directory creation and file listing

4.3 🧱 chunk_history.py

  • ➕ Logs chunk addition, retrieval, and assembly
  • 💾 Tracks saving and loading of chunk history

4.4 🎨 banner.py

  • 🖼️ Logs the creation and display of visual elements
  • 👤 Tracks user-specific banner generation

4.5 🤖 ollama_client.py

  • 🌐 Logs API requests and responses
  • ⏲️ Tracks processing times for Ollama interactions

5. ✨ Best Practices

5.1 📝 Log Message Format

  • 🎯 Be concise and descriptive
  • 🔢 Include relevant variable values
  • 🔤 Use consistent terminology

Example:

logger.info(f"Processing file: {filename}")

5.2 🔒 Sensitive Information

  • 🚫 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

5.3 🚀 Performance Considerations

  • 😴 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()}")

5.4 🚨 Error Logging

  • 📜 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)}")

6. 📊 Log Management

6.1 🔄 Log Rotation

Implement log rotation to manage log file sizes:

from logging.handlers import RotatingFileHandler

file_handler = RotatingFileHandler(LOG_FILE, maxBytes=10*1024*1024, backupCount=5)

6.2 📈 Log Analysis

Regularly review logs for:

  • 🐞 Error patterns
  • 🐢 Performance bottlenecks
  • 🕵️ Unusual activity

Consider using log analysis tools for large-scale systems.

7. 🔮 Future Enhancements

  • 🧱 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

8. 🎉 Conclusion

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.