logging
最后更新
luxonis_ml.utils.logging函数
deprecated
Python
1def deprecated(*args: str, suggest: dict[str, str] | None = None, additional_message: str | None = None, altogether: bool = False) -> Callable[[Callable], Callable]:示例
Python
1decorator = deprecated(
2 "old_arg",
3 "another_old_arg",
4 suggest={"old_arg": "new_arg"},
5 additional_message="不鼓励使用 'old_arg'。",
6)
7
8def my_func(old_arg, another_old_arg, new_arg=None):
9 pass
10
11my_func = decorator(my_func)
12my_func("foo")
13
14# DeprecationWarning: 函数 `my_func` 中的参数 'old_arg' 已弃用,
15# 并将在未来版本中移除。
16# 请改用 'new_arg'。
17# 不鼓励使用 'old_arg'。*args(str): 已弃用参数的名称。suggest(dict[str, str] | None): 建议的替换参数。additional_message(str | None): 要附加到警告消息的额外消息。altogether(bool): 如果为 True,则将整个函数标记为已弃用。
Callable[[Callable], Callable]: 发出弃用警告的装饰器。
log_once
Python
1def log_once(logger: Callable[[str], None], message: str):logger(Callable[[str], None]): 要使用的记录器。message(str): 要记录的消息。
setup_logging
Python
1def setup_logging(*, level: Literal['DEBUG', 'INFO', 'WARNING', 'ERROR', 'CRITICAL'] | None = None, file: PathType | None = None, use_rich: bool = True, pretty_validation_errors: bool = True, **kwargs):level(Literal['DEBUG', 'INFO', 'WARNING', 'ERROR', 'CRITICAL'] | None): 日志级别。如果未设置,则从环境变量LOG_LEVEL读取。file(PathType | None): 日志文件路径。如果提供,日志将保存到此文件。use_rich(bool): 如果为 True,则使用 rich 进行日志记录。pretty_validation_errors(bool): 如果为 True,则在未捕获的 pydantic 验证错误后打印可读摘要。**kwargs: 传递给RichHandler的其他关键字参数。
ValueError: 如果日志级别无效。