0

それは私のコードですが、ログファイルにはNoneが多すぎます。なぜですか? どうすれば削除できますか?

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