当前位置: 首页 > 文档资料 > Tornado 用户手册 >

tornado.log — Logging support

优质
小牛编辑
131浏览
2023-12-01

Logging support for Tornado.

Tornado uses three logger streams:

  • tornado.access: Per-request logging for Tornado’s HTTP servers (and potentially 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 errors or warnings from Tornado itself.

These streams may be configured independently using the standard library’s module. For example, you may wish to send tornado.access logs to 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 support when logging to a terminal that supports it.
  • Timestamps on every log line.
  • Robust against str/bytes encoding problems.

This formatter is enabled automatically by or (unless --logging=none is used).

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

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

tornado.log.enable_pretty_logging(options=None, logger=None)

Turns on formatted logging output as configured.

This is called automatically by and .

tornado.log.define_logging_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 .

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