duplicate output in simple python logging configuration

前端 未结 3 2064
刺人心
刺人心 2020-12-09 16:20

I\'m setting up python logging as follows:

def setup_logging():
    loggers = (logging.getLogger(\"amcat\"), logging.getLogger(\"scrapers\"),logging.getLogge         


        
3条回答
  •  囚心锁ツ
    2020-12-09 16:27

    Basically, when one of your child logger displays a message, it goes backwards in the hierarchy, and the parents are also logging the same thing.

    To cancel that behavior, you can add this:

    logger.propagate = False
    

    When it hits the child, it won't hit the parent afterwards.

    Here is some documentation about this behavior.

提交回复
热议问题