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_loggingto 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: Falseto default settings infunctions_settings.py - Added form handling in
route_frontend_admin_settings.py - Added UI toggle in
admin_settings.htmlLogging tab
2. Debug Helper Functions
Created functions_debug.py with two main functions:
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:
# 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 settingfunctions_debug.py- New debug helper functionsroute_frontend_admin_settings.py- Form handlingadmin_settings.html- UI toggleconfig.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
- Navigate to Admin Settings
- Click on the "Logging" tab
- Toggle "Enable Debug Logging" on/off as needed
- Changes take effect immediately
For Developers
- Import the debug function:
from functions_debug import debug_print - Replace
debug_print(f"message")withdebug_print("message") - 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:
- Left as-is (they will still work)
- Gradually migrated to use
debug_print() - Updated during future code maintenance
This provides a smooth transition path while immediately offering the toggle functionality for any new debug statements.