Last active
September 19, 2017 18:02
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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