Skip to content

Add Debug Mode to Control File Logging #10

@naji247

Description

@naji247

Overview

MCPcat currently writes debug logs to a mcpcat.log file by default. In production environments or when debugging is not needed, this can create unnecessary disk I/O and storage usage. We need a way to control whether logs are written to file.

Current State

The logging module (src/mcpcat/modules/logging.py) automatically writes all debug information to a log file. There's no configuration option to disable this behavior, which can be problematic for:

  • Production deployments where disk I/O should be minimized
  • Containerized environments with limited storage
  • Situations where logging is handled by external systems

Requirements

Add a configuration option to control file logging:

  1. New Configuration Option

    • Add a debug_mode or enable_file_logging flag to MCPCatOptions
    • Default to current behavior (logging enabled) for backward compatibility
  2. Conditional Logging

    • Only write to file when explicitly enabled
    • Preserve all other logging functionality
  3. Environment Variable Support

    • Allow setting via environment variable (e.g., MCPCAT_DEBUG_MODE)
    • Useful for containerized deployments

Why This Matters

  • Reduces unnecessary disk I/O in production
  • Prevents log files from filling up disk space
  • Gives users control over their logging strategy
  • Improves performance when debugging isn't needed
  • Better suits cloud-native deployments

Acceptance Criteria

  • Add configuration option to MCPCatOptions
  • Modify write_to_log function to check configuration
  • Support environment variable override
  • Maintain backward compatibility (default to enabled)
  • Update documentation with new option
  • Add tests for both enabled and disabled states

Getting Started

  1. Look at the MCPCatOptions class structure
  2. Find the write_to_log function in logging module
  3. Add conditional check before file operations
  4. Consider using environment variables with os.getenv
  5. Test both configurations thoroughly

Configuration Examples

The option should support patterns like:

# Disable file logging
track(server, project_id="...", options={
    "debug_mode": False  # or "enable_file_logging": False
})

# Via environment variable
MCPCAT_DEBUG_MODE=false

Notes

  • Consider what happens to existing log files when disabled
  • Think about whether to log this configuration choice itself
  • Ensure error handling still works when logging is disabled
  • Keep the implementation simple and performant

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions