Skip to content

Instantly share code, notes, and snippets.

@kdahlhaus
Last active September 19, 2017 18:02
Show Gist options
  • Save kdahlhaus/f4ccbc56e34ca8c57267fc6aacf90100 to your computer and use it in GitHub Desktop.
Save kdahlhaus/f4ccbc56e34ca8c57267fc6aacf90100 to your computer and use it in GitHub Desktop.
How I control logging of my app and third-party libraries in a python program
import logging
# options are here:
# https://docs.python.org/3/library/logging.html#formatter-objects
formatter = logging.Formatter('%(levelname)8s %(name)s %(pathname)s %(funcName)s | %(message)s')
def configure_logger_with_name(logger_name, level=logging.DEBUG):
ch = logging.StreamHandler()
ch.setFormatter(formatter)
logger = logging.getLogger(logger_name)
logger.addHandler(ch)
logger.setLevel(level)
# configure main and library loggers
configure_logger_with_name("em")
configure_logger_with_name("yapsy-sidecarless", logging.WARN)
configure_logger_with_name("remi.request", logging.WARN)
configure_logger_with_name("remi.server.ws", logging.DEBUG)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment