Interface Automation python logging module related --logging

# Author: Dian small box off the mark 
# Time: 2020/3/26 10:26 am
# Version: 1.0
# Features:
# file: logggg.py


Import logging
# a: log level
five rank # log, and gradually increase
logging.debug ( 'debug level log')
logging.info ( 'info level log')
logging.warning ( 'level warning log')
logging.error ( 'error level log')
logging.critical ( 'Critical level log ')
# execute pycharm result: print only warning above
# wARNING: root: log warning level
# ERROR: root: log error level
# CRITICAL: root: critical level log

# two: creation of its own collector
# output to the console
# output to a file

# 1. Create a own log collector (If you do not pass parameters, will return to the default log collector root)
# Print (logging.getLogger ()) <rootLogger root (the WARNING )>
# = logging.getLogger MyLog ( 'My')
# Print (MyLog) <Logger my (WARNING)>

= logging.getLogger MyLog ( 'My')
# 2. Set Level
mylog.setLevel ( 'WARNING') # to uppercase Note
# 3. Output
# output to a file
fh = logging.FileHandler ( 'mylog.log', encoding = 'UTF-. 8')
fh.setLevel ( 'ERROR')
mylog.addHandler (FH)

# output to the console
SH = logging.StreamHandler ()
sh.setLevel ( 'the WARNING')
mylog.addHandler (SH)

# 4. format configuration of input log
Formats = '% (the asctime) S - [% (filename) S -> Line:% (lineno) D] -% (levelname) S:% (Message) S'
form logging.Formatter = ( Formats)
fh.setFormatter (form)
sh.setFormatter (form)















Guess you like

Origin www.cnblogs.com/xiaoduanhe/p/12575463.html