首页 > 代码库 > python log模块

python log模块

import logging #added by chowhan at 2017-05-03

import logging.handlers

LOG_FILE = "/home/alice/tensorflow_logger.log"

handler = logging.handlers.RotatingFileHandler(LOG_FILE, maxBytes = 1024*1024, backupCount = 5) # 实例化handler

fmt = ‘%(asctime)s - %(filename)s:%(lineno)s - %(name)s - %(message)s‘

formatter = logging.Formatter(fmt) # 实例化formatter
handler.setFormatter(formatter) # 为handler添加formatter

logger = logging.getLogger(‘zihan‘) # 获取名为tst的logger
logger.addHandler(handler) # 为logger添加handler
logger.setLevel(logging.DEBUG)

 

#打印log

logger.debug(‘-------------------------------------------‘)

python log模块