python第二十四天-----作業終於完成啦
阿新 • • 發佈:2017-05-27
critical pan tle div bug 關聯 記錄 創建 pla
1 #!usr/bin/env python 2 #-*-coding:utf-8-*- 3 # Author calmyan 4 #日誌記錄相關函數 5 import os,logging,time 6 from conf import config 7 8 def log_file_():#檢測文件是否存在 9 if os.path.exists(config.USER_ERRO):#確認用戶錯誤日誌文件是否存在 10 with open(config.USER_ERRO,‘w‘,encoding=‘utf-8‘) as user_history:#View Code創建一個用戶錯誤日誌文件 11 user_history.write(‘‘)#寫入空值 12 pass 13 if os.path.exists(config.USER_OPERT):#確認用戶操作日誌文件是否存在 14 with open(config.USER_OPERT,‘w‘,encoding=‘utf-8‘) as user_infor:#創建一個用戶操作日誌文件 15 user_infor.write(‘‘)#寫入空值 16 if os.path.exists(config.USER_LOG):#確認用戶登陸日誌文件是否存在 17 with open(config.USER_LOG,‘w‘,encoding=‘utf-8‘) as user_infor:#創建一個用戶登陸日誌文件 18 user_infor.write(‘‘)#寫入空值 19 20 if os.path.exists(config.ADMIN_ERRO):#確認管理員錯誤日誌文件是否存在 21 with open(config.ADMIN_ERRO,‘w‘,encoding=‘utf-8‘) as user_infor:#創建一個管理員錯誤日誌文件22 user_infor.write(‘‘)#寫入空值 23 pass 24 if os.path.exists(config.ADMIN_LOG):#確認管理員登陸日誌文件是否存在 25 with open(config.ADMIN_LOG,‘w‘,encoding=‘utf-8‘) as user_infor:#創建一個管理員登陸日誌文件 26 user_infor.write(‘‘)#寫入空值 27 pass 28 if os.path.exists(config.ADMIN_OPERT):#確認管理員操作日誌文件是否存在 29 with open(config.ADMIN_OPERT,‘w‘,encoding=‘utf-8‘) as user_infor:#創建一個管理員操作日誌文件 30 user_infor.write(‘‘)#寫入空值 31 pass 32 else: 33 34 pass 35 36 def log_err(info_str):#錯誤日誌,傳入的錯誤內容 37 logger=logging.getLogger(‘用戶登陸錯誤日誌‘)#設置日誌模塊 38 logger.setLevel(logging.DEBUG) 39 fh=logging.FileHandler(config.USER_ERRO,encoding=‘utf-8‘)#寫入文件 40 fh.setLevel(logging.DEBUG)#寫入信息的級別 41 fh_format=logging.Formatter(‘%(asctime)s %(message)s‘,datefmt=‘%m/%d/%Y %I:%M:%S %p‘)#日誌格式 42 fh.setFormatter(fh_format)#關聯格式 43 logger.addHandler(fh)#添加日誌輸出模式 44 logger.warning(info_str) 45 return 0 46 47 def log_log(info_str):#登陸日誌,傳入內容 48 logger=logging.getLogger(‘用戶成功登陸日誌‘)#設置日誌模塊 49 logger.setLevel(logging.DEBUG) 50 fh=logging.FileHandler(config.USER_LOG,encoding=‘utf-8‘)#寫入文件 51 fh.setLevel(logging.DEBUG)#寫入信息的級別 52 fh_format=logging.Formatter(‘%(asctime)s %(message)s‘,datefmt=‘%m/%d/%Y %I:%M:%S %p‘)#日誌格式 53 fh.setFormatter(fh_format)#關聯格式 54 logger.addHandler(fh)#添加日誌輸出模式 55 logger.warning(info_str) 56 return 0 57 58 def user_opert(info_str):#用戶操作日誌,傳入內容 59 logger=logging.getLogger(‘用戶操作日誌‘)#設置日誌模塊 60 logger.setLevel(logging.CRITICAL) 61 fh=logging.FileHandler(config.USER_OPERT,encoding=‘utf-8‘)#寫入文件 62 fh.setLevel(logging.CRITICAL)#寫入信息的級別 63 fh_format=logging.Formatter(‘%(asctime)s %(message)s‘,datefmt=‘%m/%d/%Y %I:%M:%S %p‘)#日誌格式 64 fh.setFormatter(fh_format)#關聯格式 65 logger.addHandler(fh)#添加日誌輸出模式 66 logger.critical(info_str) 67 return 0 68 69 70 71 def admin_log(info_str):#管理員登陸日誌,傳入內容 72 logger=logging.getLogger(‘管理員成功登陸日誌‘)#設置日誌模塊 73 logger.setLevel(logging.DEBUG) 74 fh=logging.FileHandler(config.ADMIN_LOG,encoding=‘utf-8‘)#寫入文件 75 fh.setLevel(logging.DEBUG)#寫入信息的級別 76 fh_format=logging.Formatter(‘%(asctime)s %(message)s‘,datefmt=‘%m/%d/%Y %I:%M:%S %p‘)#日誌格式 77 fh.setFormatter(fh_format)#關聯格式 78 logger.addHandler(fh)#添加日誌輸出模式 79 logger.warning(info_str) 80 return 0 81 82 def admin_err(info_str):#管理員錯誤日誌,傳入的錯誤內容 83 logger=logging.getLogger(‘管理員登陸錯誤日誌‘)#設置日誌模塊 84 logger.setLevel(logging.DEBUG) 85 fh=logging.FileHandler(config.ADMIN_ERRO,encoding=‘utf-8‘)#寫入文件 86 fh.setLevel(logging.DEBUG)#寫入信息的級別 87 fh_format=logging.Formatter(‘%(asctime)s %(message)s‘,datefmt=‘%m/%d/%Y %I:%M:%S %p‘)#日誌格式 88 fh.setFormatter(fh_format)#關聯格式 89 logger.addHandler(fh)#添加日誌輸出模式 90 logger.warning(info_str) 91 return 0 92 93 def admin_opert(info_str):#管理員操作日誌,傳入內容 94 logger=logging.getLogger(‘管理員操作日誌‘)#設置日誌模塊 95 logger.setLevel(logging.CRITICAL) 96 fh=logging.FileHandler(config.ADMIN_OPERT,encoding=‘utf-8‘)#寫入文件 97 fh.setLevel(logging.CRITICAL)#寫入信息的級別 98 fh_format=logging.Formatter(‘%(asctime)s %(message)s‘,datefmt=‘%m/%d/%Y %I:%M:%S %p‘)#日誌格式 99 fh.setFormatter(fh_format)#關聯格式 100 logger.addHandler(fh)#添加日誌輸出模式 101 logger.critical(info_str) 102 return 0
python第二十四天-----作業終於完成啦