tornado.log
— 日誌記錄支援¶
Tornado 的日誌記錄支援。
Tornado 使用三個記錄器串流
tornado.access
:針對 Tornado 的 HTTP 伺服器(以及未來可能其他的伺服器)的每個請求記錄。tornado.application
:記錄應用程式程式碼中的錯誤(例如,回呼函式中未捕獲的例外)。tornado.general
:通用日誌記錄,包括來自 Tornado 本身的任何錯誤或警告。
這些串流可以使用標準函式庫的 logging
模組進行獨立設定。例如,您可能希望將 tornado.access
日誌傳送到單獨的檔案進行分析。
- class tornado.log.LogFormatter(fmt: str = '%(color)s[%(levelname)1.1s %(asctime)s %(module)s:%(lineno)d]%(end_color)s %(message)s', datefmt: str = '%y%m%d %H:%M:%S', style: str = '%', color: bool = True, colors: Dict[int, int] = {10: 4, 20: 2, 30: 3, 40: 1, 50: 5})[來源]¶
在 Tornado 中使用的日誌格式器。
此格式器的主要功能是
當記錄到支援終端機時,支援色彩。
每行日誌上的時間戳記。
針對 str/bytes 編碼問題的穩固性。
此格式器會由
tornado.options.parse_command_line
或tornado.options.parse_config_file
自動啟用(除非使用--logging=none
)。在不支援 ANSI 色碼的 Windows 版本上,藉由使用 colorama 函式庫啟用色彩支援。想要使用此功能的應用程式必須先呼叫
colorama.init
初始化 colorama。如需詳細資訊,請參閱 colorama 文件。在 4.5 版本變更: 新增了對
colorama
的支援。變更了建構函式簽名,使其與logging.config.dictConfig
相容。- 參數
在 3.2 版本變更: 新增了
fmt
和datefmt
引數。
- tornado.log.enable_pretty_logging(options: Optional[Any] = None, logger: Optional[Logger] = None) None [來源]¶
根據設定開啟格式化的日誌輸出。
這會由
tornado.options.parse_command_line
和tornado.options.parse_config_file
自動呼叫。