python log模塊
阿新 • • 發佈:2017-06-20
home 添加 打印 backup orm level mat lin --
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模塊