Python中log的使用

  • Logging

    Logging is a means of tracking events that happen when some software runs.

    Events also have an importance which the developer ascribes to the events, the importance can also be called the levels or severity.

    The standard levels and their applicability are described below(in increasing order of severity):

    Level When it’s used Numeric Value
    NOTSET 0
    DEBUG Detailed information,typically of interest only when diagnosing problems 10
    INFO Confirmation that things are working as expeted 20
    WARNING(default level) An indication that something unexpencted happened, or indicative of some problem in the near future(e.g. ‘disk space low’), The software is still working as expected. 30
    ERROR Due to a more serious problem, the software has not been able to perform some function. 40
    CRITICAL A serious error,indicating that the program itself may be unable to continue running. 50

    Events that are tracked can be handled in different ways,like printing them to the console or writing them to a disk file.

  • logging:Logging facility for Python

    logging is the Python standard library implementing Logging.

    The basic classes defined by the module,together with their functions,are listed below:

    • Loggers expose the interface that application code directly uses.
    • Handlers send the log records(created by loggers) to the appropriate destination.
    • Filters provide a finer grained facility for determining which log records to output.
    • Formatters specify the layout of log records in the final output.
  • Reference

  1. logging — Logging facility for Python
  2. Logging HOWTO
  3. Logging Cookbook
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章