Skip to main content

Overview

The logger module provides a simple, user-friendly logging interface built on the Rich library. It supports color-coded log levels, formatted output, and animated status indicators. Source: docugen/utils/logger.py

DocuGenLogger

class DocuGenLogger:
    def __init__(self) -> None
Main logging class with Rich console output.

Attributes

console
rich.console.Console
Rich Console instance used for all output rendering.

Methods

info()

def info(self, message: str) -> None
Log informational message with cyan “INFO” prefix.
message
str
required
Message to log.
Output format: [cyan]INFO[/] {message}

warning()

def warning(self, message: str) -> None
Log warning message with yellow “WARN” prefix.
message
str
required
Warning message to log.
Output format: [yellow]WARN[/] {message}

error()

def error(self, message: str) -> None
Log error message with red “ERROR” prefix.
message
str
required
Error message to log.
Output format: [red]ERROR[/] {message}

success()

def success(self, message: str) -> None
Log success message with green “OK” prefix.
message
str
required
Success message to log.
Output format: [green]OK[/] {message}

status()

def status(self, message: str)
Create an animated status indicator context manager.
message
str
required
Status message to display with spinner.
return
rich.console.Status
Rich Status context manager with “dots” spinner animation.
Usage: Use with with statement for automatic cleanup.

get_logger()

def get_logger() -> DocuGenLogger
Factory function to create a new logger instance.

Returns

return
DocuGenLogger
New DocuGenLogger instance.

Usage Examples

Basic Logging

from docugen.utils.logger import get_logger

logger = get_logger()

logger.info("Starting documentation generation...")
logger.warning("No .env file found, using environment variables")
logger.error("API key not configured")
logger.success("README.md generated successfully")
Output:
INFO Starting documentation generation...
WARN No .env file found, using environment variables
ERROR API key not configured
OK README.md generated successfully

Status Indicator

from docugen.utils.logger import get_logger
import time

logger = get_logger()

# Animated spinner during long operations
with logger.status("Analyzing codebase..."):
    time.sleep(3)  # Simulate work
    # Spinner shows "dots" animation

logger.success("Analysis complete")

In Application Code

from docugen.utils.logger import get_logger
from pathlib import Path

def generate_docs(project_path: Path) -> None:
    logger = get_logger()
    
    logger.info(f"Processing project: {project_path}")
    
    if not project_path.exists():
        logger.error("Project path does not exist")
        return
    
    with logger.status("Generating documentation with AI..."):
        # AI generation logic here
        result = call_gemini_api()
    
    if result.success:
        logger.success(f"Documentation written to {result.output_path}")
    else:
        logger.error(f"Generation failed: {result.error}")

Log Level Colors

LevelPrefixColorUse Case
info()INFOCyanGeneral information, progress updates
warning()WARNYellowNon-critical issues, deprecations
error()ERRORRedFailures, exceptions, critical problems
success()OKGreenSuccessful operations, completions

Rich Console Features

The logger uses Rich’s Console for:
  • Color and styling - Automatic terminal color support detection
  • Unicode support - Emoji and special characters
  • Width detection - Automatic terminal width adaptation
  • Status animations - Smooth spinner rendering

Design Notes

  • No file output - All logging goes to console only
  • Stateless - Each get_logger() call creates independent instance
  • Simple API - No log levels, configuration, or filtering
  • User-focused - Designed for CLI output, not debugging

Build docs developers (and LLMs) love