Python: logging log level details

Source: Internet
Author: User
Import  Logging  '''  Log Level: critical> error> warning> info> Debug. The higher the notset level, the fewer logs are printed, and vice versa. That is, debug: prints all logs (notset is equivalent to debug) info: print info, warning, error, and critical-level logs warning: Print warning, error, and critical-level log error: print error, critical-level log critical: print the critical-level log  '''  Handler = Logging. filehandler ( "  // Tmp/TNLOG-error.log  "  )  Def  Log (level): Logger =Logging. getlogger ()  #  Handler cannot be created repeatedly. Otherwise, the same record will be written repeatedly?  Logger. addhandler (handler) Logger. setlevel (level) Logger. debug (  "  Debug  "  ) Logger.info (  "  Info  "  ) Logger. Warning (  "  Warning  " ) Logger. Error (  "  Error  "  ) Logger. Critical (  "  Critical \ n  "  )  If   _ Name __ = "  _ Main __  " : Log (logging. notset) log (logging. Debug) log (logging. info) log (logging. Warning) log (logging. Error) log (logging. Critical) 

InProgramIn the development phase, we obviously need a large number of logs, so the log level should be Debug. When the system is gradually stable, we need to reduce the number of logs to be recorded, in this way, the program execution efficiency can be improved (I don't think we should delete the debug-level log statements because they will be required again during maintenance? AlthoughCodeI think a good system should have such a statement.) At this time, we are more concerned with the user's actions in the system and what the user has done, if our program is a website that can buy things, we need to record all the information related to money, that is, users' modifications to core data must be recorded, at this time, we can select logs of info or above and the most important information. Obviously, we need to select the critical level. How to divide the logs depends on the system design, I don't have much experience to talk about it, but I suggest using the error level for the exception part (try-try t). Even if the system runs normally, unexpected errors cannot be guaranteed, once low-level logs are selected, the cause of important system exceptions may be missed.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.