标签:file get 实例化 bytes nbsp set -- formatter 模块
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(‘-------------------------------------------‘)
标签:file get 实例化 bytes nbsp set -- formatter 模块
原文地址:http://www.cnblogs.com/xuehongxuan/p/7050919.html