# DEBUG LOGGING TOGGLE FEATURE

> A new feature that allows administrators to enable or disable debug print statements across the entire SimpleChat application through the admin settings interface.

- Skill: `tools-only/debug-logging-toggle-feature` (Agent Skill, multi-file: 3 files)
- Install (CLI): `npx skillmds@latest add tools-only/debug-logging-toggle-feature`
- Raw SKILL.md: https://api.skillmd.com/api/skills/tools-only/debug-logging-toggle-feature/raw
- Safety review: pending (external: skill-scanner PASS, skillspector PASS)
- Works with: Claude Code, Claude.ai, OpenAI Codex
- Category: Coding & Dev Tools
- Author: tools-only (https://skillmd.com/u/tools-only)
- Updated: 2026-09-29
- Page: https://skillmd.com/skills/tools-only/debug-logging-toggle-feature

---

# DEBUG LOGGING TOGGLE FEATURE

**Version Implemented:** 0.229.001

## Overview
A new feature that allows administrators to enable or disable debug print statements across the entire SimpleChat application through the admin settings interface.

**Fixed/Implemented in version: 0.228.015**

## Problem Solved
Previously, debug print statements using `debug_print(f"...")` were hardcoded throughout the application and could not be turned on or off without code changes. This made it difficult to:
- Control debug output in production environments
- Enable debugging only when needed for troubleshooting
- Reduce console noise during normal operation
- Provide a clean way to manage development vs. production logging

## Solution
Implemented a centralized debug logging toggle that:
- Adds a setting `enable_debug_logging` to the admin settings
- Provides a UI toggle in the admin settings Logging tab
- Creates helper functions to conditionally print debug messages
- Allows real-time control of debug output without code changes

## Technical Implementation

### 1. Settings Integration
- Added `enable_debug_logging: False` to default settings in `functions_settings.py`
- Added form handling in `route_frontend_admin_settings.py`
- Added UI toggle in `admin_settings.html` Logging tab

### 2. Debug Helper Functions
Created `functions_debug.py` with two main functions:

```python
def debug_print(message):
    """Print debug message only if debug logging is enabled"""
    
def is_debug_enabled():
    """Check if debug logging is enabled"""
```

### 3. Admin UI
Added a new toggle in the admin settings Logging tab:
- Toggle switch to enable/disable debug logging
- Info tooltip explaining the feature
- Blue info alert explaining usage
- Positioned alongside Application Insights logging

### 4. Usage Pattern
Replace existing debug prints:
```python
# Before:
debug_print(f"Some debug message")

# After:
from functions_debug import debug_print
debug_print("Some debug message")
```

## Files Modified

### Core Implementation
- `functions_settings.py` - Added default setting
- `functions_debug.py` - New debug helper functions
- `route_frontend_admin_settings.py` - Form handling
- `admin_settings.html` - UI toggle
- `config.py` - Updated version

### Example Usage
- `route_backend_chats.py` - Updated several debug prints to use new system

### Testing
- `test_debug_logging_toggle.py` - Comprehensive functional test

## Usage Instructions

### For Administrators
1. Navigate to Admin Settings
2. Click on the "Logging" tab
3. Toggle "Enable Debug Logging" on/off as needed
4. Changes take effect immediately

### For Developers
1. Import the debug function: `from functions_debug import debug_print`
2. Replace `debug_print(f"message")` with `debug_print("message")`
3. Use `is_debug_enabled()` for conditional debug blocks

## Benefits
- **Performance**: No debug output overhead when disabled
- **Clean Logs**: Reduces console noise in production
- **Flexibility**: Enable debugging only when troubleshooting
- **Centralized Control**: Single setting controls all debug output
- **Backward Compatible**: Existing debug prints still work
- **Safe**: Error handling prevents crashes if settings unavailable

## Testing Coverage
- Debug function behavior when enabled/disabled
- Settings integration and default values
- Error handling for configuration issues
- UI toggle functionality
- Real-time control verification

## Migration Path
Existing `debug_print(f"...")` statements can be:
1. Left as-is (they will still work)
2. Gradually migrated to use `debug_print()` 
3. Updated during future code maintenance

This provides a smooth transition path while immediately offering the toggle functionality for any new debug statements.
