本文介绍了如何在Python中为特定模块实现不同级别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从这个 stackoverflow问题,一个人如何实现以下配置文件?

From this stackoverflow question, how does one implement the following configuration file?

[logger_qpid]
level=NOTSET
handlers=nullHandler
qualname=qpid
propagate=0

我正在使用logging.basicConfig:

I am using logging.basicConfig:

# Configure parser.
parser = argparse.ArgumentParser(description = 'Allow for debug logging mode.')
parser.add_argument('--debug', action = 'store_true',
                    help = 'Outputs additional information to log.')
c_args = parser.parse_args()
# Configure logging mode.
if c_args.debug:
    # Enable debug level of logging.
    print "Logging level set to debug."
    logging.basicConfig(filename = LOG_FILENAME, format = '%(asctime)s %(message)s',
                        level = logging.DEBUG)
else:
    logging.basicConfig(filename = LOG_FILENAME, format = '%(asctime)s %(message)s',
                        level = logging.INFO)

推荐答案

在suds程序包的文档站点中,可以使用setLevel方法设置特定程序包的级别.例如,以下是将所有肥皂水的记录级别设置为INFO级别(在logging.basicConfig()代码之后的位置)的方法:

From the suds package's documentation site, you can set the level for a specific package by using the setLevel method. For example, here's how to set the level of all suds logging to INFO level (place after logging.basicConfig() code):

logging.getLogger('suds').setLevel(logging.INFO)

这篇关于如何在Python中为特定模块实现不同级别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-29 07:14