31

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 Answer 1

50

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)
2
  • or use it like >>> import mymodule logging.getLogger(mymodule.__name__)
    – ntakouris
    Commented Jul 7, 2022 at 9:24
  • will this still be filtered by the root logger, say we set the log level for a module to loging.DEBUG, but the root logger is configured for logging.INFO? I'm hoping there's a way to remap the log traces in a module to count them as info just for that one module.
    – jxramos
    Commented Jun 11 at 5:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.