您好,登录后才能下订单哦!
密码登录
登录注册
点击 登录注册 即表示同意《亿速云用户服务条款》
#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进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。