Spaces:
Sleeping
Sleeping
| """ | |
| Central Logging Configuration | |
| """ | |
| import logging | |
| import sys | |
| from config import LOGGING_ENABLED | |
| def setup_logging(): | |
| """ | |
| Configure logging based on LOGGING_ENABLED flag in config. | |
| If enabled, logs to both file (smurf_village.log) and console. | |
| If disabled, sets logging level to CRITICAL to suppress all logs. | |
| """ | |
| if LOGGING_ENABLED: | |
| # Configure logging to file and console | |
| logging.basicConfig( | |
| level=logging.INFO, | |
| format='%(asctime)s - %(name)s - %(levelname)s - %(message)s', | |
| handlers=[ | |
| logging.FileHandler('smurf_village.log'), | |
| logging.StreamHandler(sys.stdout) | |
| ], | |
| force=True # Override any existing configuration | |
| ) | |
| else: | |
| # Disable logging by setting level to CRITICAL | |
| logging.basicConfig( | |
| level=logging.CRITICAL, | |
| handlers=[logging.NullHandler()], | |
| force=True | |
| ) | |