给内库增加日志功能-gb 50150-2016电气装置安装工程电气设备交接试验标准
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() >>>
4.84MB
文件大小:
评论区