20191011- build our own automated testing framework -Config Interface Configuration

Config modules primarily to a number of other configurations such as a directory to store the current directory to store log configuration file

################################################
[loggers]
keys=root,example01,example02
[logger_root]
level=DEBUG
handlers=hand01,hand02
[logger_example01]
handlers=hand01,hand02
qualname=example01
propagate=0
[logger_example02]
handlers=hand01,hand03
qualname=example02
propagate=0
###############################################
[handlers]
keys=hand01,hand02,hand03
[handler_hand01]
class=StreamHandler
level=DEBUG
formatter=form01
args=(sys.stderr,)
[handler_hand02]
class=FileHandler
level=DEBUG
formatter=form01
args=('C:\\Users\\HYJ\\Desktop\\Onapi\\Log\\AutomationTestLog.log', 'a')
[handler_hand03]
class=handlers.RotatingFileHandler
level=INFO
formatter=form01
args=('C:\\Users\\HYJ\\Desktop\\Onapi\\Log\\AutomationTestLog.log', 'a', 10*1024*1024, 5)
###############################################
[formatters]
keys=form01,form02
[formatter_form01]
format=%(asctime)s %(filename)s[line:%(lineno)d] %(levelname)s %(message)s
datefmt=%Y-%m-%d %H:%M:%S
[formatter_form02]
format=%(name)-12s: %(levelname)-8s %(message)s
datefmt=%Y-%m-%d %H:%M:%S

In format, the output directory, the contents of the output form like configuration defined log

Log.py corresponding to the following documents:

# Encoding = UTF-8 
# logging module learning website: HTTPS: //cloud.tencent.com/developer/article/1354396 
Import logging.config
 Import logging
 from ProVar.ProjConfigVar Import * 

logging.config.fileConfig (conf_path) 
Logger = logging .getLogger ( " example01 " )
 # Loggers: logger configuration information. Must contain a name, called the root logger, when using non-parametric function logging.getLogger (), returns the default root of this logger, other custom logger can be called by logging.getLogger ( "fileLogger") way to 
# handlers: define statement handlers information. The StreamHandler handlers include commonly used (log output only to kong console), a FileHandler (save log information output to a file), RotaRotatingFileHandler (save the log output to a file, and set the number and the size of the log file single log file wenj ) 
#formatter: Set the log format 
# logger_xxx: for logger loggers one by one declared in the configuration, and to one correspondence 
# handler_xxx: for handler handlers declared in a configuration one by one, and to one correspondence 
# formatter_xxx: formatterjinx statement to be configured 
# logging configuration files: multiple logger, each logger, specify a different Handler 
# Handler: set the output format of the log line 
# Handler: as well as to set the write log files (if rollback)? Or to the screen 
# Handler: also set the level of print logs. 
DEF debug (the Message):
     # print the log level debug method 
   Print ( " debug " ) 
   logger.debug (the Message) 

DEF warning (the Message):
     # print warning level log method 
    logger.warning (the Message) 

DEFinfo (the Message):
     # print info level log method 
    logger.info (the Message) 

DEF error (the Message):
     # Print error level log error 
    logging.error (the Message) 

IF  __name__ == " __main__ " : 
    Debug ( " hi " ) 
    info ( " gloryroad " ) 
    warning ( " the Hello " )

 

Guess you like

Origin www.cnblogs.com/hyj691001/p/11654329.html