python日志记录模块记录太多无

时间:2013-10-22 08:42:26

标签: python django logging

这是我的代码,但在日志文件中,有太多无,为什么?我怎么能删除它?

import logging, traceback, os
def loginit(trace):
    trace_len = len(trace)
    trace = trace[trace_len - 2][:2]
    callname = ((trace[0].split('/'))[-1])
    head = (callname.split('.')[0]).split('_')
    if len(head) == 1:
        logfilehead = head[0]
    else:
        logfilehead = head[1]

    lineid = trace[1]

    logger = None
    logger = logging.getLogger()
    handle = logging.FileHandler('file_name','a+')
    formatter = logging.Formatter('%(process)d [%(asctime)s %(callname)s %(lineid)d] %(levelname)s: %(message)s')
    handle.setFormatter(formatter)
    logger.addHandler(handle)
    logger.setLevel(logging.NOTSET)

    return logger,handle,{'lineid':lineid, 'callname':callname}

def DEBUG(msg, *args):
    if config.LOG_LEVEL < 5:return
    logger, handle, extra = loginit(traceback.extract_stack())
    kwargs = {'extra':extra, 'exc_info':1}
    logger.debug(msg, *args, **kwargs)
    handle.flush()
    logger.removeHandler(handle)
    logging.shutdown()
  

3650 [2013-09-11 02:06:12,357 dispatch.py​​ 137]错误:开始* * **

     

3650 [2013-09-11 02:06:12,359 dispatch.py​​ 173]错误:操作:登录* **

     

3650 [2013-09-11 02:07:09,273 dispatch.py​​ 184]错误: * ** *

0 个答案:

没有答案