-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlogging_config.py
More file actions
33 lines (24 loc) · 1023 Bytes
/
logging_config.py
File metadata and controls
33 lines (24 loc) · 1023 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
"""Central logging setup for Agent Zero CLI."""
import logging
import os
from pathlib import Path
LOG_FILE = Path("logs") / "agentzero.log"
def setup_logging(force: bool = False) -> None:
"""Configure logging handlers (console + optional debug file)."""
root = logging.getLogger()
if root.handlers and not force:
return
is_debug = os.environ.get("AGENTZERO_DEBUG", "0").lower() in ("1", "true", "yes")
level = logging.DEBUG if is_debug else logging.INFO
root.setLevel(level)
formatter = logging.Formatter("[%(asctime)s] %(levelname)s %(name)s: %(message)s")
console = logging.StreamHandler()
console.setLevel(level)
console.setFormatter(formatter)
root.addHandler(console)
if level == logging.DEBUG:
LOG_FILE.parent.mkdir(parents=True, exist_ok=True)
file_handler = logging.FileHandler(LOG_FILE, encoding="utf-8")
file_handler.setLevel(logging.DEBUG)
file_handler.setFormatter(formatter)
root.addHandler(file_handler)