Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

How to configure logging file in python

Shulou Source: shulou.com Published: 2022-06-02 07:45:53 11月01日 Update

Python how to configure logging files, I believe that many inexperienced people do not know what to do, so this article summarizes the causes of the problem and solutions, through this article I hope you can solve this problem.

Logging.conf

[loggers] keys=root,cping, API [logger _ root] level=DEBUGhandlers= stream [logger _ cping] handlers=stream,filequalname=cpingpropagate= 0 [logger _ api] handlers=stream,filequalname=cpingpropagate=0## [handlers] keys=stream, file [handler _ stream] class=StreamHandlerlevel=INFOformatter=standardargs= (sys.stdout,) [handler_file] class=cping.utils.log_helper.MyLoggerHandlerlevel=INFOformatter=standardargs= ('logs/cping.log',' MONTH' 36) # # [formatters] keys= standard [formatter _ standard] format=% (asctime) s -% (name) s -% (levelname) s -% (message) sdatefmt=

Use

Import loggingimport logging.configlogging.config.fileConfig ('logging.conf') # create loggerlogger = logging.getLogger (' cping') # 'application' codelogger.debug (' debug message') logger.info ('info message') logger.warning (' warn message') logger.error ('error message') logger.critical (' critical message')

Note: root must be configured, otherwise an error will be reported

Logging.config.fileConfig ('logging.conf') File "/ usr/lib/python2.7/logging/config.py, line 86, in fileConfig _ install_loggers (cp, handlers, disable_existing_loggers) File" / usr/lib/python2.7/logging/config.py ", line 190, in _ install_loggers llist.remove (" root ") ValueError: list.remove (x): x not in list after reading the above, have you mastered how to configure logging files in python? If you want to learn more skills or want to know more about it, you are welcome to follow the industry information channel, thank you for reading!

Tags: Configuration documents content methods more problems helplessness for this reason skills articles experience industry information information channels channels Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Apple MariaDB OPPO Reno Xiaomi macOS