first commit
This commit is contained in:
47
public_web/app/utils/logging.py
Normal file
47
public_web/app/utils/logging.py
Normal file
@@ -0,0 +1,47 @@
|
||||
"""
|
||||
Logging utilities for public web frontend.
|
||||
|
||||
Simplified logging wrapper using structlog.
|
||||
"""
|
||||
|
||||
import structlog
|
||||
import logging
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
def setup_logging():
|
||||
"""Configure structured logging for the web frontend."""
|
||||
structlog.configure(
|
||||
processors=[
|
||||
structlog.processors.TimeStamper(fmt="iso"),
|
||||
structlog.processors.add_log_level,
|
||||
structlog.processors.StackInfoRenderer(),
|
||||
structlog.dev.ConsoleRenderer()
|
||||
],
|
||||
wrapper_class=structlog.make_filtering_bound_logger(logging.INFO),
|
||||
context_class=dict,
|
||||
logger_factory=structlog.PrintLoggerFactory(),
|
||||
cache_logger_on_first_use=True,
|
||||
)
|
||||
|
||||
|
||||
def get_logger(name: str):
|
||||
"""
|
||||
Get a logger instance.
|
||||
|
||||
Args:
|
||||
name: Logger name (usually __file__)
|
||||
|
||||
Returns:
|
||||
Configured structlog logger
|
||||
"""
|
||||
if isinstance(name, str) and name.endswith('.py'):
|
||||
# Extract module name from file path
|
||||
name = Path(name).stem
|
||||
|
||||
return structlog.get_logger(name)
|
||||
|
||||
|
||||
# Setup logging on module import
|
||||
setup_logging()
|
||||
Reference in New Issue
Block a user