您好,登錄后才能下訂單哦!
#Author Kang
import logging
logging.basicConfig(filename="app.log",level=logging.WARNING,format='%(asctime)s %(levelname)s: %(message)s', datefmt='%m/%d/%Y %I:%M:%S %p')
logging.info("app info test")
logging.warning("app warning message")
logging.error("app error message")
#filename:app.log文件,用于保存日志輸出信息
#level:日志級別
#format:日志輸出的格式
結果:app.log文件信息
02/18/2019 06:27:10 PM WARNING: app warning message
02/18/2019 06:27:10 PM ERROR: app error message
import logging
from logging.handlers import TimedRotatingFileHandler
class Log():
def __init__(self):
self.logger = logging.getLogger('Operation Mail')
self.logger.setLevel(logging.INFO)
ch = TimedRotatingFileHandler("access.log", when='D', encoding="utf-8")
ch.setLevel(logging.DEBUG)
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
ch.setFormatter(formatter)
self.logger.addHandler(ch)
def debug(self,log_msg):
self.logger.debug(log_msg)
def info(self,log_msg):
self.logger.info(log_msg)
def error(self,log_msg):
self.logger.error(log_msg)
def cirtical(self,log_msg):
self.logger.critical(log_msg)
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。