-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlogging.py
More file actions
39 lines (29 loc) · 1.07 KB
/
Copy pathlogging.py
File metadata and controls
39 lines (29 loc) · 1.07 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
"""Structured logging configuration for PyAgent."""
import logging
import sys
def configure_logging(level: str = "INFO") -> None:
"""Configure the root logger for the application.
Call once at the application entry point. All modules should obtain
their logger via ``get_logger(__name__)``.
Args:
level: Log level name (DEBUG, INFO, WARNING, ERROR, CRITICAL).
"""
root = logging.getLogger("pyagent")
if root.handlers:
return
handler = logging.StreamHandler(sys.stderr)
formatter = logging.Formatter(
"%(asctime)s | %(name)s | %(levelname)s | %(message)s",
datefmt="%Y-%m-%d %H:%M:%S",
)
handler.setFormatter(formatter)
root.addHandler(handler)
root.setLevel(getattr(logging, level.upper(), logging.INFO))
def get_logger(name: str) -> logging.Logger:
"""Return a logger scoped under the ``pyagent`` namespace.
Args:
name: Typically ``__name__`` of the calling module.
Returns:
A configured ``logging.Logger`` instance.
"""
return logging.getLogger(f"pyagent.{name}")