简体   繁体   中英

Ignore logging.basicConfig in third party module

I am importing a third party module that I don't have control over and can't change the source. It does a logging.basicConfig() which is messing up my own logger configuration. I have tried giving a different 'name' to my logger using self.logger = logging.getLogger('some_random_name') which is resulting in every log message printed twice, once with my format, and once with the format set by the basicConfig in that third party module.

Is there a way to ignore the basicConfig from the imported module?

logging.basicConfig() implicitly add handlers to the root logger, so you can just delete those handlers by logging.root.handlers = [] .


Further, the root logger may set to an unwanted level, you can also simply set it by logging.root.setLevel(what_ever_you_want) .


Even further, if you call logging.info , logging.error etc. without configuring the root logger first, a basicConfig() is called internally, and so a StreamHandler will be implicitly added to the root logger.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM