1 #! Usr/bin/env python2 #-*-coding:utf-8-*-3 #Author Calmyan4 #Logging related functions5 ImportOs,logging,time6 fromConfImportConfig7 8 defLog_file_ ():#detects if a file exists9 ifOs.path.exists (config. User_erro):#Verify that the user error log file existsTenwith open (config. User_erro,'W', encoding='Utf-8') as User_history:#Create a user error log file OneUser_history.write ("')#Write null value A Pass - ifOs.path.exists (config. User_opert):#Verify that the user action log file exists -with open (config. User_opert,'W', encoding='Utf-8') as User_infor:#Create a user action log file theUser_infor.write ("')#Write null value - ifOs.path.exists (config. User_log):#Verify that the user log file exists -with open (config. User_log,'W', encoding='Utf-8') as User_infor:#Create a user login log file -User_infor.write ("')#Write null value + - ifOs.path.exists (config. Admin_erro):#Verify that the administrator error log file exists +with open (config. Admin_erro,'W', encoding='Utf-8') as User_infor:#Create an administrator error log file AUser_infor.write ("')#Write null value at Pass - ifOs.path.exists (config. Admin_log):#Verify that the Administrator log file exists -with open (config. Admin_log,'W', encoding='Utf-8') as User_infor:#Create an administrator login log file -User_infor.write ("')#Write null value - Pass - ifOs.path.exists (config. Admin_opert):#confirm that the Administrator action log file exists inwith open (config. Admin_opert,'W', encoding='Utf-8') as User_infor:#Create an Administrator action log file -User_infor.write ("')#Write null value to Pass + Else: - the Pass * $ defLog_err (INFO_STR):#error log, incoming error contentPanax NotoginsengLogger=logging.getlogger ('User Login error log')#set up the log module - Logger.setlevel (logging. DEBUG) theFh=logging. Filehandler (config. user_erro,encoding='Utf-8')#Write File +Fh.setlevel (logging. DEBUG)#level of writing information AFh_format=logging. Formatter ('% (asctime) s% (message) s', datefmt='%m/%d/%y%i:%m:%s%p')#Log Format theFh.setformatter (Fh_format)#Associated Formats +Logger.addhandler (FH)#Add log output mode - logger.warning (INFO_STR) $ return0 $ - defLog_log (INFO_STR):#login log, incoming content -Logger=logging.getlogger ('User login log successfully')#set up the log module the Logger.setlevel (logging. DEBUG) -Fh=logging. Filehandler (config. user_log,encoding='Utf-8')#Write FileWuyiFh.setlevel (logging. DEBUG)#level of writing information theFh_format=logging. Formatter ('% (asctime) s% (message) s', datefmt='%m/%d/%y%i:%m:%s%p')#Log Format -Fh.setformatter (Fh_format)#Associated Formats WuLogger.addhandler (FH)#Add log output mode - logger.warning (INFO_STR) About return0 $ - defUser_opert (INFO_STR):#user action log, incoming content -Logger=logging.getlogger ('User Action Log')#set up the log module - Logger.setlevel (logging. CRITICAL) AFh=logging. Filehandler (config. user_opert,encoding='Utf-8')#Write File +Fh.setlevel (logging. CRITICAL)#level of writing information theFh_format=logging. Formatter ('% (asctime) s% (message) s', datefmt='%m/%d/%y%i:%m:%s%p')#Log Format -Fh.setformatter (Fh_format)#Associated Formats $Logger.addhandler (FH)#Add log output mode the logger.critical (INFO_STR) the return0 the the - in defAdmin_log (INFO_STR):#Admin login log, incoming content theLogger=logging.getlogger ('administrator logs in successfully')#set up the log module the Logger.setlevel (logging. DEBUG) AboutFh=logging. Filehandler (config. admin_log,encoding='Utf-8')#Write File theFh.setlevel (logging. DEBUG)#level of writing information theFh_format=logging. Formatter ('% (asctime) s% (message) s', datefmt='%m/%d/%y%i:%m:%s%p')#Log Format theFh.setformatter (Fh_format)#Associated Formats +Logger.addhandler (FH)#Add log output mode - logger.warning (INFO_STR) the return0Bayi the defAdmin_err (INFO_STR):#Administrator error log, incoming error content theLogger=logging.getlogger ('Administrator Login error log')#set up the log module - Logger.setlevel (logging. DEBUG) -Fh=logging. Filehandler (config. admin_erro,encoding='Utf-8')#Write File theFh.setlevel (logging. DEBUG)#level of writing information theFh_format=logging. Formatter ('% (asctime) s% (message) s', datefmt='%m/%d/%y%i:%m:%s%p')#Log Format theFh.setformatter (Fh_format)#Associated Formats theLogger.addhandler (FH)#Add log output mode - logger.warning (INFO_STR) the return0 the the defAdmin_opert (INFO_STR):#Administrator action Log, incoming content94Logger=logging.getlogger ('Administrator Action Log')#set up the log module the Logger.setlevel (logging. CRITICAL) theFh=logging. Filehandler (config. admin_opert,encoding='Utf-8')#Write File theFh.setlevel (logging. CRITICAL)#level of writing information98Fh_format=logging. Formatter ('% (asctime) s% (message) s', datefmt='%m/%d/%y%i:%m:%s%p')#Log Format AboutFh.setformatter (Fh_format)#Associated Formats -Logger.addhandler (FH)#Add log output mode101 logger.critical (INFO_STR)102 return0
View Code
Python is finally finished on the 24th day of-----.