0

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

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] 错误:* ** *

4

0 回答 0