python-logging- base (1)

In the implementation of use cases often encounter various problems encountered after the problem is difficult to locate

 

import logging

class Logs:

the __init __ DEF (Self, filepath, name):
# the self.name name =
# = self.filepath filepath
self.config = read_config (Config_Http)
# log redefined name
self.logger = logging.getLogger (self.config.get_value ( ' log ',' logger_name '))
# log collection specified level
self.logger.setLevel (logging.DEBUG)
# log output is provided to place the console
SH = logging.StreamHandler ()
# set the console log level of the output error
sh.setLevel (logging.error)
# set the log file storage address
FH = logging.FileHandler (the os.path.join (Log_Filepath, self.config.get_value ( 'log', 'file_name')), encoding = 'UTF-. 8')
# log storage level is set to file inside info
fh.setLevel (logging.info)
# redefine the output format settings log
# 1. simple log information, primarily for console view
formatter_01 = logging.Formatter (self.config.get_value ( 'log', 'st_formater '))
# 2. Complex log information, primarily to document View Details
formatter_02 = logging.Formatter (self.config.get_value ( 'log', 'fh_formater'))
# Console to set up a simple log output format information
sh.setFormatter (formatter_01 )
# set the log file to the log book format complicated information
fh.setFormatter (formatter_02)
self.logger.addHandler (SH)
self.logger.addHandler (FH)
DEF get_logger (Self):
"" "

:return:
"""
return self.logger


the __name__ == IF '__ main__':
Logger = Logs ()
logger.debug ( "This is a debug level log information")
logger.info ( "This is an info level log information")
logger.warning ( "This is the a warning level log information ")
logger.error (" this is an error level log information ")
logger.critical (" this is a critical level log information ")

Guess you like

Origin www.cnblogs.com/newsss/p/12113852.html