Python #logging

###spa

 
 
#-*- coding:utf-8 -*-
import logging
import logging.handlers
#日誌目錄
LOG_FILE ='log.zk'
log_fmt='%(asctime)s - %(filename)s - %(levelname)s - %(message)s'
date_fmt='%a, %d %b %Y %H:%M:%S'
#實例化formatter,datefmt的格式是使用yime.strftime(format[, t])的格式
formatter=logging.Formatter(fmt=log_fmt,datefmt=date_fmt)
# Thu, 21 Sep 2017 10:46:29 - LOG.py - ERROR - The ERROR MESSAGE
#建立一個Handler處理器
handler = logging.handlers.RotatingFileHandler(LOG_FILE)
# 爲handler添加日誌格式
handler.setFormatter(formatter)
#建立一個logger實例
logger = logging.getLogger('log.zk')
#設置日誌級別
logger.setLevel(logging.ERROR)
#添加一個處理器
logger.addHandler(handler)

logger.debug('The DEBUG MESSAGE')
logger.info('The INFO MESSAGE')
logger.warning('The WARN MESSAGE')
logger.error('The ERROR MESSAGE')
logger.critical('The critical MESSAGE')

###.net

 
 
#-*- coding:utf-8 -*-
import logging
import logging.handlers
# filename:日誌名稱,level 日誌等級(輸出INFO以上的日誌包括INFO)
logging.basicConfig(filename='log.kafka',level=logging.INFO,format='%(asctime)s - %(filename)s - %(levelname)s - %(message)s')
logging.debug('The DEBUG MESSAGE')
logging.info('The INFO MESSAGE')
logging.warning('The WARN MESSAGE')
logging.error('The ERROR MESSAGE')
logging.critical('The critical MESSAGE')

 

###debug

參考博客:日誌

http://blog.csdn.net/zyz511919766/article/details/25136485code

相關文章
相關標籤/搜索