### Navigation
- [index](# "General Index")
- [modules](# "Python Module Index") |
- [next](# "tornado.options — Command-line parsing") |
- [previous](# "tornado.autoreload — Automatically detect code changes in development") |
- [Tornado 4.4.dev1 documentation](#) »
- [Utilities](#) »
# `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's[`logging`](https://docs.python.org/3.4/library/logging.html#module-logging "(in Python v3.4)") [https://docs.python.org/3.4/library/logging.html#module-logging] 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}*)[[source]](#)
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[`tornado.options.parse_command_line`](# "tornado.options.parse_command_line") (unless `--logging=none` isused).
<table class="docutils field-list" frame="void" rules="none"><col class="field-name"/><col class="field-body"/><tbody valign="top"><tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple"><li><strong>color</strong> (<a class="reference external" href="https://docs.python.org/3.4/library/functions.html#bool" title="(in Python v3.4)"><em>bool</em></a><span class="link-target"> [https://docs.python.org/3.4/library/functions.html#bool]</span>) – Enables color support.</li><li><strong>fmt</strong> (<a class="reference external" href="https://docs.python.org/3.4/library/string.html#module-string" title="(in Python v3.4)"><em>string</em></a><span class="link-target"> [https://docs.python.org/3.4/library/string.html#module-string]</span>) – Log message format.It will be applied to the attributes dict of log records. Thetext between <code class="docutils literal"><span class="pre">%(color)s</span></code> and <code class="docutils literal"><span class="pre">%(end_color)s</span></code> will be coloreddepending on the level if color support is on.</li><li><strong>colors</strong> (<a class="reference external" href="https://docs.python.org/3.4/library/stdtypes.html#dict" title="(in Python v3.4)"><em>dict</em></a><span class="link-target"> [https://docs.python.org/3.4/library/stdtypes.html#dict]</span>) – color mappings from logging level to terminal colorcode</li><li><strong>datefmt</strong> (<a class="reference external" href="https://docs.python.org/3.4/library/string.html#module-string" title="(in Python v3.4)"><em>string</em></a><span class="link-target"> [https://docs.python.org/3.4/library/string.html#module-string]</span>) – Datetime format.Used for formatting <code class="docutils literal"><span class="pre">(asctime)</span></code> placeholder in <code class="docutils literal"><span class="pre">prefix_fmt</span></code>.</li></ul></td></tr></tbody></table>
Changed in version 3.2: Added `fmt` and `datefmt` arguments.
`tornado.log.``enable_pretty_logging`(*options=None*, *logger=None*)[[source]](#)
Turns on formatted logging output as configured.
This is called automatically by [`tornado.options.parse_command_line`](# "tornado.options.parse_command_line")and [`tornado.options.parse_config_file`](# "tornado.options.parse_config_file").
`tornado.log.``define_logging_options`(*options=None*)[[source]](#)
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`](# "tornado.options.OptionParser").
New in version 4.2: This function existed in prior versions but was broken and undocumented until 4.2.
© Copyright 2009-2016, The Tornado Authors. Created using [Sphinx](http://sphinx-doc.org/) 1.3.5.
- User's guide
- Introduction
- Asynchronous and non-Blocking I/O
- Coroutines
- Queue example - a concurrent web spider
- Structure of a Tornado web application
- Templates and UI
- Authentication and security
- Running and deploying
- Web framework
- tornado.web — RequestHandler and Application classes
- tornado.template — Flexible output generation
- tornado.escape — Escaping and string manipulation
- tornado.locale — Internationalization support
- tornado.websocket — Bidirectional communication to the browser
- HTTP servers and clients
- tornado.httpserver — Non-blocking HTTP server
- tornado.httpclient — Asynchronous HTTP client
- tornado.httputil — Manipulate HTTP headers and URLs
- tornado.http1connection – HTTP/1.x client/server implementation
- Asynchronous networking
- tornado.ioloop — Main event loop
- tornado.iostream — Convenient wrappers for non-blocking sockets
- tornado.netutil — Miscellaneous network utilities
- tornado.tcpclient — IOStream connection factory
- tornado.tcpserver — Basic IOStream-based TCP server
- Coroutines and concurrency
- tornado.gen — Simplify asynchronous code
- tornado.concurrent — Work with threads and futures
- tornado.locks – Synchronization primitives
- tornado.queues – Queues for coroutines
- tornado.process — Utilities for multiple processes
- Integration with other services
- tornado.auth — Third-party login with OpenID and OAuth
- tornado.wsgi — Interoperability with other Python frameworks and servers
- tornado.platform.asyncio — Bridge between asyncio and Tornado
- tornado.platform.caresresolver — Asynchronous DNS Resolver using C-Ares
- tornado.platform.twisted — Bridges between Twisted and Tornado
- Utilities
- tornado.autoreload — Automatically detect code changes in development
- tornado.log — Logging support
- tornado.options — Command-line parsing
- tornado.stack_context — Exception handling across asynchronous callbacks
- tornado.testing — Unit testing support for asynchronous code
- tornado.util — General-purpose utilities
- Frequently Asked Questions
- Release notes
- What's new in Tornado 4.3
- What's new in Tornado 4.2.1
- What's new in Tornado 4.2
- What's new in Tornado 4.1
- What's new in Tornado 4.0.2
- What's new in Tornado 4.0.1
- What's new in Tornado 4.0
- What's new in Tornado 3.2.2
- What's new in Tornado 3.2.1
- What's new in Tornado 3.2
- What's new in Tornado 3.1.1
- What's new in Tornado 3.1
- What's new in Tornado 3.0.2
- What's new in Tornado 3.0.1
- What's new in Tornado 3.0
- What's new in Tornado 2.4.1
- What's new in Tornado 2.4
- What's new in Tornado 2.3
- What's new in Tornado 2.2.1
- What's new in Tornado 2.2
- What's new in Tornado 2.1.1
- What's new in Tornado 2.1
- What's new in Tornado 2.0
- What's new in Tornado 1.2.1
- What's new in Tornado 1.2
- What's new in Tornado 1.1.1
- What's new in Tornado 1.1
- What's new in Tornado 1.0.1
- What's new in Tornado 1.0