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'));
some of these debug messages come from function_a() and others from function_b(); i'd like to be able to enable/disable logging based on whether they come from a or from b;
i'm guessing that i have to use logging's filtering mechanism;
can someone please show me how the code below would need to be instrumented to do what i want? thanks.
import logging
logger= logging.getLogger( "module_name" )
def function_a( ... ):
logger.debug( "a message" )
def function_b( ... ):
logger.debug( "another message" )
if __name__ == "__main__":
logging.basicConfig( stream=sys.stderr, level=logging.DEBUG )
#don't want function_a()'s noise -> ....
#somehow filter-out function_a's logging
function_a()
#don't want function_b()'s noise -> ....
#somehow filter-out function_b's logging
function_b()
if i scaled this simple example to more modules and more funcs per module, i'd be concerned about lots of loggers;
can i keep it down to 1 logger per module? note that the log messages are "structured", i.e. if the function(s) logging it are doing some parsing work, they all contain a prefix logger.debug("parsing: xxx") - can i somehow with a single line just shut-off all "parsing" messages (regardless of the module/function emitting the message?)