Skip to content

Enhanced Centralized Logging System #9

Description

@hmshuv

Implement Centralized Logging System for strategicwm

Problem Description

Currently, the strategicwm library uses a mix of print statements and optional logging.Logger objects passed as arguments to functions (e.g., in client_lib.py). This ad-hoc approach leads to several issues:

  • Inconsistent Output: Difficult to control verbosity levels globally across the library
  • Integration Challenges: Harder for consumers of the library to capture or redirect logs programmatically
  • Debugging Difficulty: Lack of standardized timestamps and log levels makes tracing execution flows more challenging
  • Maintenance Burden: Mixed logging approaches create technical debt and reduce code quality

Proposed Solution

Implement a centralized logging configuration for the library with the following components:

1. Global Logger Configuration

Create a module-level logger setup (e.g., strategicwm.get_logger()) that ensures consistent formatting and handling across all modules.

2. Replace Print Statements

Systematically replace print(..., flush=True) calls with appropriate logging methods:

  • logger.debug() for detailed diagnostic information
  • logger.info() for general informational messages
  • logger.warning() for warning messages
  • logger.error() for error conditions

3. User Configurability

Allow users to easily configure logging levels (DEBUG, INFO, WARNING, ERROR) without modifying library code, following Python's standard logging best practices.

Implementation Details

Step 1: Create Logging Utility

Define a logging utility module at _src/utils/logging.py (or similar location) with:

import logging
from typing import Optional

def get_logger(name: str, level: Optional[int] = None) -> logging.Logger:
    """Get or create a logger with standardized configuration."""
    logger = logging.getLogger(name)
    if level is not None:
        logger.setLevel(level)
    return logger

def configure_logging(level: int = logging.INFO, format_string: Optional[str] = None):
    """Configure library-wide logging settings."""
    # Implementation here
    pass

Step 2: Update Existing Modules

  • Update client_lib.py and other modules to use the centralized logging utility
  • Replace all print statements used for logging purposes with appropriate logger calls
  • Audit codebase for any remaining ad-hoc logging patterns

Step 3: Backward Compatibility

  • Ensure backward compatibility where possible
  • If the logger argument in functions needs to be deprecated, clearly document breaking changes
  • Provide migration guide for users currently passing logger objects

Step 4: Documentation

  • Add logging configuration documentation to README or docs
  • Provide examples of how users can configure logging for their use cases
  • Document any breaking changes in CHANGELOG

Acceptance Criteria

  • All print statements used for logging purposes are replaced with logging calls
  • Centralized logging utility is implemented in _src/utils/logging.py
  • Users can control log verbosity via standard Python logging configuration
  • Logging format includes timestamps, log levels, and module names
  • All existing tests pass without modification
  • New tests are added to verify logging behavior and output capture
  • Documentation is updated with logging configuration examples
  • Backward compatibility is maintained or breaking changes are clearly documented

Additional Context

This enhancement will significantly improve the library's maintainability and make it easier for users to integrate strategicwm into production environments where proper logging is essential.

Related Files

  • client_lib.py
  • Any other modules currently using print statements for logging

Labels: enhancement, good-first-issue, logging, code-quality
Difficulty: Medium
Estimated Effort: 4-8 hours

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions