-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlogger.py
More file actions
33 lines (26 loc) · 905 Bytes
/
logger.py
File metadata and controls
33 lines (26 loc) · 905 Bytes
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
import logging
import sys
from src.config import AppConfig
def setup_logging():
"""Setup logging configuration"""
# Create logs directory
log_dir = AppConfig.PROJECT_ROOT / "logs"
log_dir.mkdir(exist_ok=True)
if logging.getLogger().handlers:
return
# Configure logging
logging.basicConfig(
level=getattr(logging, AppConfig.LOG_LEVEL.upper()),
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
handlers=[
logging.FileHandler(log_dir / "app.log", encoding='utf-8'),
logging.StreamHandler(sys.stderr)
]
)
logger = logging.getLogger(__name__)
logger.info(f"✅ Logging initialized - Level: {AppConfig.LOG_LEVEL} - Log dir: {log_dir}")
def get_logger(name: str) -> logging.Logger:
"""Get logger instance"""
return logging.getLogger(name)
# Auto setup
setup_logging()