python logging
Posted 青盏
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python logging相关的知识,希望对你有一定的参考价值。
# coding: utf-8
import os
import sys
import logging
# from logging.handlers import TimedRotatingFileHandler
from concurrent_log_handler import ConcurrentRotatingFileHandler
str_def_fmt = "%(asctime)s %(thread)d %(levelname)s " \\
"%(filename)s:%(lineno)d %(funcName)s: %(message)s"
log_path = os.getcwd() + "/log/run.log"
# handle = TimedRotatingFileHandler(log_path, when = 'H', interval = 1, backupCount = 6)
# handle.suffix = "%Y-%m-%d_%H-%M"
handle = ConcurrentRotatingFileHandler(log_path, mode = "a", maxBytes = 128*1024, backupCount = 6)
def should_log(record):
if record.module in ["meta_client"]:
return False
return True
log_filter = logging.Filter()
log_filter.filter = should_log
handle.addFilter(log_filter)
logging.basicConfig(level=logging.ERROR,
format=str_def_fmt,
datefmt="%Y:%m:%d %H:%M:%S",
handlers=[handle])
# stream=sys.stdout)
logger = logging.getLogger("logger")
logger.setLevel(logging.INFO)
以上是关于python logging的主要内容,如果未能解决你的问题,请参考以下文章