Skip to content

Instantly share code, notes, and snippets.

@m3adow
Last active August 29, 2015 14:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save m3adow/b96fa376d9f9e254b47f to your computer and use it in GitHub Desktop.
Save m3adow/b96fa376d9f9e254b47f to your computer and use it in GitHub Desktop.
Logging - How does it work?
import logging
LOG = logging.getLogger('A')
ch = logging.StreamHandler()
formatter = logging.Formatter('%(asctime)s %(levelname)s %(name)s: %(message)s')
ch.setFormatter(formatter)
LOG.addHandler(ch)
LOG.setLevel("DEBUG")
from functions import common_functions
common_functions.loggertest()
import logging
LOG = logging.getLogger('B')
ch = logging.StreamHandler()
formatter = logging.Formatter('%(levelname)s %(name)s: %(message)s %(asctime)s')
ch.setFormatter(formatter)
LOG.addHandler(ch)
LOG.setLevel("WARN")
from functions import common_functions
common_functions.loggertest()
import logging
LOG = logging.getLogger('whichnamehere')
LOG.addHandler(logging.NullHandler())
def loggertest():
LOG.info("This should be printed with proper formatting.")
LOG.debug("This debug message as well.")
LOG.warn("This should be the only message visible for B.py")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment