Python logging module is printing lines multiple times

后端 未结 4 737
南旧
南旧 2021-01-01 17:53

I have the following code:

import logging
class A(object):
    def __init__(self):
        self._l = self._get_logger()

    def _get_logger(self):
        l         


        
4条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-01-01 18:28

    In my case , the root loggers handler were also being called , All I did was to set propagate attribute of logger instance to False.

    import logging
    logger = logging.getLogger("MyLogger")
    
    # stop propagting to root logger
    logger.propagate = False
    
    # other log configuration stuff
    # ....
    

提交回复
热议问题