I\'m using Logging (import logging) to log messages.
Within 1 single module, I am logging messages at the debug level my_logger.debug(\'msg\')
Do not use global. It's an accident waiting to happen.
You can give your loggers any "."-separated names that are meaningful to you.
You can control them as a hierarchy. If you have loggers named a.b.c and
a.b.d, you can check the logging level for a.b and alter both loggers.
You can have any number of loggers -- they're inexpensive.
The most common design pattern is one logger per module. See Naming Python loggers
Do this.
import logging
logger= logging.getLogger( "module_name" )
logger_a = logger.getLogger( "module_name.function_a" )
logger_b = logger.getLogger( "module_name.function_b" )
def function_a( ... ):
logger_a.debug( "a message" )
def function_b( ... ):
logger_b.debug( "another message" )
if __name__ == "__main__":
logging.basicConfig( stream=sys.stderr, level=logging.DEBUG )
logger_a.setLevel( logging.DEBUG )
logger_b.setLevel( logging.WARN )
... etc ...