How to implement different levels for specific modules in Python

会有一股神秘感。 提交于 2019-11-30 01:17:54

问题


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

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

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)

回答1:


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)


来源:https://stackoverflow.com/questions/7234262/how-to-implement-different-levels-for-specific-modules-in-python

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!