当前位置:   article > 正文

python多线程logger_python 使用logging多线程写多个log文件

python多线程logger

import threading

import time

import logging

import logging.handlers

LEVELS={'notset':logging.DEBUG,

'debug':logging.DEBUG,

'info':logging.INFO,

'warning':logging.WARNING,

'error':logging.ERROR,

'critical':logging.CRITICAL}

LOG_FILENAME = 'test.log'

LOG_BACKUPCOUNT = 5

LOG_LEVEL = 'notset'

def InitLog(file_name,logger):

LOG_FILENAME = file_name

handler = logging.handlers.RotatingFileHandler(LOG_FILENAME,maxBytes=10*1024*1024,backupCount=LOG_BACKUPCOUNT)

#handler = logging.FileHandler(LOG_FILENAME)

formatter = logging.Formatter("[ %(asctime)s ][ %(levelname)s ] %(message)s\n")

handler.setFormatter(formatter)

#logger = logging.getLogger()

logger.addHandler(handler

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/酷酷是懒虫/article/detail/963162
推荐阅读
相关标签
  

闽ICP备14008679号