tornado.log — Logging support¶

Logging support for Tornado.

Tornado uses three logger streams:

  • tornado.access: Per-request logging for Tornado’s HTTP servers (andpotentially other servers in the future)
  • tornado.application: Logging of errors from application code (i.e.uncaught exceptions from callbacks)
  • tornado.general: General-purpose logging, including any errorsor warnings from Tornado itself.
    These streams may be configured independently using the standard library’slogging module. For example, you may wish to send tornado.access logsto a separate file for analysis.
    class tornado.log.LogFormatter(color=True, fmt='%(color)s[%(levelname)1.1s %(asctime)s %(module)s:%(lineno)d]%(end_color)s %(message)s', datefmt='%y%m%d %H:%M:%S', colors={40: 1, 10: 4, 20: 2, 30: 3})[源代码]

    Log formatter used in Tornado.

Key features of this formatter are:

参数:
  • color (bool) – Enables color support.
  • fmt (string) – Log message format.It will be applied to the attributes dict of log records. Thetext between %(color)s and %(end_color)s will be coloreddepending on the level if color support is on.
  • colors (dict) – color mappings from logging level to terminal colorcode
  • datefmt (string) – Datetime format.Used for formatting (asctime) placeholder in prefix_fmt.

在 3.2 版更改: Added fmt and datefmt arguments.

tornado.log.enablepretty_logging(_options=None, logger=None)[源代码]

Turns on formatted logging output as configured.

This is called automatically by tornado.options.parse_command_lineand tornado.options.parse_config_file.

tornado.log.definelogging_options(_options=None)[源代码]

Add logging-related flags to options.

These options are present automatically on the default options instance;this method is only necessary if you have created your own OptionParser.

4.2 新版功能: This function existed in prior versions but was broken and undocumented until 4.2.

原文:

https://tornado-zh-cn.readthedocs.io/zh_CN/latest/log.html