-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup_logging.py
More file actions
51 lines (40 loc) · 1.39 KB
/
setup_logging.py
File metadata and controls
51 lines (40 loc) · 1.39 KB
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
"""
Logging setup for NeuraX Multimodal RAG System.
Provides setup_logging() to configure loguru and get_logger(name) for
component-specific loggers.
"""
import sys
def setup_logging():
"""Initialize logging configuration using loguru."""
try:
from loguru import logger
from config import LOGGING_CONFIG, LOGS_DIR
# Remove default handler
logger.remove()
# Ensure logs directory exists
LOGS_DIR.mkdir(parents=True, exist_ok=True)
# Add file handler
log_file = LOGS_DIR / "neurax.log"
logger.add(
log_file,
level=LOGGING_CONFIG["level"],
format=LOGGING_CONFIG["format"],
rotation=LOGGING_CONFIG.get("rotation", "10 MB"),
retention=LOGGING_CONFIG.get("retention", "1 week"),
compression=LOGGING_CONFIG.get("compression", "gz"),
)
# Add console handler
logger.add(
sys.stderr,
level=LOGGING_CONFIG["level"],
format=LOGGING_CONFIG["format"],
)
logger.info("Logging system initialized")
return True
except Exception as e:
print(f"Failed to setup logging: {e}", file=sys.stderr)
return False
def get_logger(name: str):
"""Return a loguru logger bound with the given component/module name."""
from loguru import logger
return logger.bind(name=name)