Created
July 3, 2017 08:54
-
-
Save yeondudad/5d271f15d2fb3fd97839fb826aad6466 to your computer and use it in GitHub Desktop.
propagate test
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 sys | |
import logging | |
parent_logger = logging.getLogger("parent") | |
parent_logger.setLevel(logging.DEBUG) | |
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s') | |
handler = logging.StreamHandler(sys.stdout) | |
handler.setLevel(logging.DEBUG) | |
handler.setFormatter(formatter) | |
parent_logger.addHandler(handler) | |
parent_logger.debug("parent Debug!!") | |
parent_logger.info("parent Info!!") | |
child_logger1 = logging.getLogger("parent.child1") | |
child_logger1.addHandler(handler) | |
child_logger1.propagate = True | |
child_logger1.debug("This is from child1!") | |
child_logger2 = logging.getLogger("parent.child2") | |
child_logger2.addHandler(handler) | |
child_logger2.propagate = False | |
child_logger2.debug("This is from child2!") | |
# 2017-07-03 17:53:33,796 - parent - DEBUG - parent Debug!! | |
# 2017-07-03 17:53:33,797 - parent - INFO - parent Info!! | |
# 2017-07-03 17:53:33,797 - parent.child1 - DEBUG - This is from child1! | |
# 2017-07-03 17:53:33,797 - parent.child1 - DEBUG - This is from child1! | |
# 2017-07-03 17:53:33,797 - parent.child2 - DEBUG - This is from child2! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment