Python logging.FileHandler 参考
Python logging.FileHandler 参考,整理标准库调用语法、参数、示例、返回值和常见错误。
语法
import logging
handler = logging.FileHandler("app.log", encoding="utf-8")
参数
name:日志器名称,通常使用__name__。level / handler:日志级别和输出处理器。
返回值
返回 Logger、Handler 或 None;日志是否输出取决于级别和 handler 配置。
示例
import logging
logger = logging.getLogger("app")
logger.addHandler(logging.FileHandler("app.log", encoding="utf-8"))
常见错误
- basicConfig 只在根日志器未配置时生效。
- exception 需要在 except 块中调用,才能带上堆栈。
相关内容
相关内容
- Python collections.ChainMap 参考 Python collections.ChainMap 参考,整理标准库调用语法、参数、示例、返回值和常见错误。
- Python collections.Counter 参考 Python collections.Counter 参考,整理标准库调用语法、参数、示例、返回值和常见错误。
- Python collections.defaultdict 参考 Python collections.defaultdict 参考,整理标准库调用语法、参数、示例、返回值和常见错误。
- Python collections.deque 参考 Python collections.deque 参考,整理标准库调用语法、参数、示例、返回值和常见错误。
- Python collections.most_common 参考 Python collections.most_common 参考,整理标准库调用语法、参数、示例、返回值和常见错误。
- Python collections.namedtuple 参考 Python collections.namedtuple 参考,整理标准库调用语法、参数、示例、返回值和常见错误。