MCPcopy Create free account
hub / github.com/PaddlePaddle/FastDeploy / __init__

Method __init__

fastdeploy/logger/handlers.py:36–74  ·  view source on GitHub ↗

初始化日志处理器 Args: filename (str): 日志文件基础路径 backupDays (int): 保留天数,默认7天 interval (int): 日志分割间隔小时数,必须能被24整除,默认1小时 encoding (str): 文件编码,默认utf-8 delay (bool): 是否延迟打开文件,默认False utc (bool): 是否使用UTC时间,默认False

(
        self,
        filename,
        backupDays=7,
        interval=1,
        encoding="utf-8",
        delay=False,
        utc=False,
        **kwargs,
    )

Source from the content-addressed store, hash-verified

34 """
35
36 def __init__(
37 self,
38 filename,
39 backupDays=7,
40 interval=1,
41 encoding="utf-8",
42 delay=False,
43 utc=False,
44 **kwargs,
45 ):
46 """
47 初始化日志处理器
48
49 Args:
50 filename (str): 日志文件基础路径
51 backupDays (int): 保留天数,默认7天
52 interval (int): 日志分割间隔小时数,必须能被24整除,默认1小时
53 encoding (str): 文件编码,默认utf-8
54 delay (bool): 是否延迟打开文件,默认False
55 utc (bool): 是否使用UTC时间,默认False
56 """
57 if 24 % interval != 0:
58 raise ValueError("interval必须能被24整除")
59
60 self.backup_days = backupDays
61 self.interval = interval
62 self.utc = utc
63 self.base_path = Path(filename)
64 self.current_day = self._get_current_day()
65 self.current_hour = self._get_current_hour()
66 self.current_dir = self._get_day_dir()
67 self.current_filename = self._get_hourly_filename()
68 self.current_filepath = self.current_dir / self.current_filename
69 self.last_clean_time = 0 # 初始化为0确保第一次会执行清理
70 self.seconds_per_hour = 3600
71 # 确保目录存在
72 self.current_dir.mkdir(parents=True, exist_ok=True)
73
74 BaseRotatingHandler.__init__(self, str(self.current_filepath), "a", encoding, delay)
75
76 def _get_current_time(self):
77 """获取当前时间"""

Callers

nothing calls this directly

Calls 5

_get_current_dayMethod · 0.95
_get_current_hourMethod · 0.95
_get_day_dirMethod · 0.95
_get_hourly_filenameMethod · 0.95
__init__Method · 0.45

Tested by

no test coverage detected