python第二十四天-----作業終於完成啦

來源:互聯網
上載者:User

標籤:操作   lap   class   成功   技術分享   dha   tor   登陸   form   

  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:#建立一個使用者錯誤記錄檔檔案 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
View Code

 

python第二十四天-----作業終於完成啦

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.