Skip to content

Instantly share code, notes, and snippets.

@themson
Last active August 29, 2015 14:05
Show Gist options
  • Save themson/82be703b284af333e142 to your computer and use it in GitHub Desktop.
Save themson/82be703b284af333e142 to your computer and use it in GitHub Desktop.
stub for using python logging object
import logging
def toggle_debug(debug_state):
logger = logging.getLogger(__file__)
if debug_state is True:
logger.setLevel(logging.DEBUG)
stream = logging.StreamHandler()
stream.setLevel(logging.NOTSET)
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s: "%(message)s"')
stream.setFormatter(formatter)
logger.addHandler(stream)
logger.debug("Debug Output: On")
else:
logger.setLevel(logging.NOTSET)
return logger
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment