Blame view

scripts/evaluation/eval_framework/logging_setup.py 1.01 KB
cdd8ee3a   tangwang   eval框架日志独立
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
  """Configure dedicated eval run logs under repo ``logs/`` (see ``constants.EVAL_*_LOG_*``)."""
  
  from __future__ import annotations
  
  import logging
  import sys
  
  from .constants import EVAL_LOG_DIR, EVAL_LOG_FILE, EVAL_VERBOSE_LOG_DIR
  
  _setup_done = False
  
  
  def setup_eval_logging() -> None:
      """Attach file + stderr handlers to ``search_eval`` once; ensure log directories exist."""
      global _setup_done
      if _setup_done:
          return
  
      EVAL_LOG_DIR.mkdir(parents=True, exist_ok=True)
      EVAL_VERBOSE_LOG_DIR.mkdir(parents=True, exist_ok=True)
  
      fmt = logging.Formatter("%(asctime)s - %(levelname)s - %(name)s - %(message)s")
      root = logging.getLogger("search_eval")
      root.setLevel(logging.INFO)
      if root.handlers:
          _setup_done = True
          return
      fh = logging.FileHandler(EVAL_LOG_FILE, encoding="utf-8")
      fh.setFormatter(fmt)
      sh = logging.StreamHandler(sys.stderr)
      sh.setFormatter(fmt)
      root.addHandler(fh)
      root.addHandler(sh)
      root.propagate = False
      _setup_done = True