Spaces:
Sleeping
Sleeping
File size: 2,031 Bytes
77a71b4 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 | """
Centralized logging utilities for the ChordMini Flask application.
This module provides consistent logging functions that adapt to production
vs development environments.
"""
import logging
import os
# Production mode detection
PRODUCTION_MODE = (
os.environ.get('FLASK_ENV', 'production') == 'production' or
os.environ.get('PORT') is not None
)
# Unified debug switch across backend
DEBUG_ENABLED = (
os.environ.get('FLASK_ENV') == 'development' or
str(os.environ.get('DEBUG', 'false')).lower() == 'true'
)
def is_debug_enabled() -> bool:
"""Return True when debug logging should be enabled regardless of PROD/DEV."""
return DEBUG_ENABLED
# Get logger for this module
logger = logging.getLogger(__name__)
def log_info(message: str) -> None:
"""
Log info message - use logger in production, print in development.
Args:
message: Message to log
"""
if PRODUCTION_MODE:
logger.info(message)
else:
print(message)
def log_error(message: str) -> None:
"""
Log error message - use logger in production, print in development.
Args:
message: Error message to log
"""
if PRODUCTION_MODE:
logger.error(message)
else:
print(message)
def log_debug(message: str) -> None:
"""Log debug messages when debug is enabled. No-op otherwise."""
if not DEBUG_ENABLED:
return
if PRODUCTION_MODE:
logger.debug(message)
else:
print(f"DEBUG: {message}")
def log_warning(message: str) -> None:
"""
Log warning message - use logger in production, print in development.
Args:
message: Warning message to log
"""
if PRODUCTION_MODE:
logger.warning(message)
else:
print(f"WARNING: {message}")
def get_logger(name: str) -> logging.Logger:
"""
Get a logger instance for a specific module.
Args:
name: Logger name (usually __name__)
Returns:
Logger instance
"""
return logging.getLogger(name) |