给内库增加日志功能-python cookbook(第3版)高清中文完整版

时间:2024-06-29 23:06:48
【文件属性】:

文件名称:给内库增加日志功能-python cookbook(第3版)高清中文完整版

文件大小:4.84MB

文件格式:PDF

更新时间:2024-06-29 23:06:48

python cookbook 第3版 高清 中文完整版

13.12 给内库增加日志功能 问题 You would like to add a logging capability to a library, but don’t want it to interfere with programs that don’t use logging. 解决方案 For libraries that want to perform logging, you should create a dedicated logger object, and initially configure it as follows: # somelib.py import logging log = logging.getLogger(__name__) log.addHandler(logging.NullHandler()) # Example function (for testing) def func(): log.critical(‘A Critical Error!’) log.debug(‘A debug message’) With this configuration, no logging will occur by default. For example: >>> import somelib >>> somelib.func() >>>


网友评论