Python logging - zhongjiajie/zhongjiajie.github.com GitHub Wiki
- logging official: Dictionary Schema Details
- How to create daily log folder in python logging
- python-HOWTO-logging
The logging library takes a modular approach and offers several categories of components: loggers, handlers, filters, and formatters.
-
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.
Log event information is passed between loggers, handlers, filters and formatters in a LogRecord instance.
Programmers can configure logging in three ways:
- Creating loggers, handlers, and formatters explicitly using Python code that calls the configuration methods listed above.
- Creating a logging config file and reading it using the fileConfig() function.
- Creating a dictionary of configuration information and passing it to the dictConfig() function.logging-config.dictConfig
官网的dictConfig有点抽象,这里有一个可以直接复制粘贴的dictConfig的例子
The logger does know str.format()
but it's best practice in Python to use this form with logging: logger.info("Hello %s", "world")
since that creates a string only when it actually gets logged. str.format()
and f-strings
create strings before they get passed to the logger, even if the string is never logged. So it's considered inefficient(低效) and not advised(建议).
参考,专门用于expection-haduler,日志等级是error,但是参数的格式是debug