Let's say I pass in a parameter of --debug to my script where I want it to display additional text when it otherwise doesn't display it by default.
Going to keep it really simple here. How do I get logger.debug to display/log? Is it just a matter of "enabling" it if --debug is passed?
import logging logger = logging.getLogger() formatter = logging.Formatter('%(asctime)s - %(levelname)s - %(message)s') fh = logging.FileHandler('xyz.log') fh.setLevel(logging.INFO) fh.setFormatter(formatter) logger.addHandler(fh) logger.error("This is an error") logger.info("Info 123") logger.debug("FYI, here's what you don't see unless you enable me.") Maybe?
fh.setLevel(logging.DEBUG) if option == 'debug' logger.debug("FYI, here's what you don't see unless you enable me.")
if option == 'debug': fh.setLevel(logging.DEBUG)?