Automated code quality improvements: Black (Code Formatter): - Reformatted 30 files to match PEP 8 style - Consistent line length (100 chars) - Consistent quote style and spacing isort (Import Sorter): - Fixed import order in 30+ files - Grouped imports: stdlib → third-party → first-party → local - Consistent multi-line import formatting Ruff (Linter): - Auto-fixed 161 issues: * Modernized type hints (List → list, Optional[X] → X | None) * Removed unused imports (json, os, typing utilities) * Updated deprecated typing imports (typing.List → list) * Simplified type annotations with | operator (Python 3.10+) - Remaining 20 issues (acceptable): * 9x unused-method-argument (callback signatures, cannot be changed) * 2x bare-except (intentional for resilience) * 2x unused-variable (will be addressed in Phase 2) * Minor simplification opportunities (not critical) Code Quality Stats: - 32 files modified - +1749/-1589 lines (net cleanup) - Code is now consistent and formatted - Ready for gradual type safety improvements (Phase 3) All changes are non-functional - pure formatting and import organization.
39 lines
1.0 KiB
Python
39 lines
1.0 KiB
Python
"""Logging setup for IoT Bridge."""
|
|
|
|
import logging
|
|
|
|
import structlog
|
|
|
|
from config import LoggingConfig
|
|
|
|
|
|
def setup_logging(config: LoggingConfig):
|
|
"""Configure structured logging with structlog."""
|
|
|
|
# Set log level
|
|
log_level = getattr(logging, config.level.upper(), logging.INFO)
|
|
logging.basicConfig(level=log_level)
|
|
|
|
# Configure structlog
|
|
if config.format == "json":
|
|
renderer = structlog.processors.JSONRenderer()
|
|
else:
|
|
renderer = structlog.dev.ConsoleRenderer()
|
|
|
|
structlog.configure(
|
|
processors=[
|
|
structlog.stdlib.filter_by_level,
|
|
structlog.stdlib.add_logger_name,
|
|
structlog.stdlib.add_log_level,
|
|
structlog.processors.TimeStamper(fmt="iso"),
|
|
structlog.processors.StackInfoRenderer(),
|
|
structlog.processors.format_exc_info,
|
|
renderer,
|
|
],
|
|
context_class=dict,
|
|
logger_factory=structlog.stdlib.LoggerFactory(),
|
|
cache_logger_on_first_use=True,
|
|
)
|
|
|
|
return structlog.get_logger()
|