Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to implement different levels for specific modules in Python

Tags:

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) 
like image 237
paragbaxi Avatar asked Aug 29 '11 18:08

paragbaxi


People also ask

What are the different types of modules in Python?

The four modules ( mod1.py , mod2.py , mod3.py and mod4.py ) are defined as previously.

How many built-in modules are there in Python?

The Python standard library contains well over 200 modules, although the exact number varies between distributions.

What is difference between module and package in Python?

A Python Module can be a simple python File (. py extension file), i.e., a combination of numerous Functions and Global variables. A Python Package is a collection of different Python modules with an __init__.py File. __init__.py Python File works as a Constructor for the Python Package.


1 Answers

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) 
like image 145
paragbaxi Avatar answered Sep 20 '22 17:09

paragbaxi