当前位置:   article > 正文

PYTHON-多个py文件使用同一个logging文件_python 多个类使用同一个log对象

python 多个类使用同一个log对象
import logging
import sys
class MyLog:
    def __init__(self):
        self.logpath=r'my.log'
        console_handler=logging.StreamHandler(sys.stdout)
        console_handler.setFormatter(logging.Formatter('%(levelname)s: %(message)s'))
        file_handler=logging.StreamHandler(self.logpath,encoding='utf-8')
        file_handler.setFormatter(logging.Formatter('%(levelname)s: %(message)s'))
        logging.basicConfig(handlers=[console_handler,file_handler])
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/爱喝兽奶帝天荒/article/detail/963194
推荐阅读
相关标签
  

闽ICP备14008679号