2015-06-08 14:09:56 +00:00
|
|
|
Examples
|
|
|
|
========
|
|
|
|
|
|
|
|
Simple Usage
|
|
|
|
------------
|
2015-06-08 17:20:03 +00:00
|
|
|
The following snippet uses :class:`sprockets.logging.ContextFilter`
|
2015-06-08 14:09:56 +00:00
|
|
|
to insert context information into a message using a
|
|
|
|
:class:`logging.LoggerAdapter` instance.
|
|
|
|
|
2015-06-08 17:20:03 +00:00
|
|
|
.. literalinclude:: ../examples/simple.py
|
2015-06-08 14:09:56 +00:00
|
|
|
|
2015-06-08 17:20:03 +00:00
|
|
|
Dictionary-based Configuration
|
|
|
|
------------------------------
|
|
|
|
This package begins to shine if you use the dictionary-based logging
|
|
|
|
configuration offered by :func:`logging.config.dictConfig`. You can insert
|
|
|
|
the custom filter and format string into the logging infrastructure and
|
|
|
|
insert context easily with :class:`logging.LoggerAdapter`.
|
2015-06-08 14:09:56 +00:00
|
|
|
|
2015-06-08 17:20:03 +00:00
|
|
|
.. literalinclude:: ../examples/tornado-app.py
|
2015-06-18 13:36:51 +00:00
|
|
|
|
|
|
|
|
|
|
|
Tornado Application JSON Logging
|
|
|
|
--------------------------------
|
|
|
|
If you're looking to log Tornado requests as JSON, the
|
|
|
|
:class:`sprockets.logging.JSONRequestFormatter` class works in conjunction with
|
2015-09-14 11:48:00 +00:00
|
|
|
the :func:`tornado_log_function` method to output all Tornado log entries as
|
2015-06-18 13:36:51 +00:00
|
|
|
JSON objects. In the following example, the dictionary-based configuration is
|
|
|
|
expanded upon to include specify the :class:`sprockets.logging.JSONRequestFormatter`
|
2015-09-14 11:48:00 +00:00
|
|
|
as the formatter and passes :func:`tornado_log_function` in as the ``log_function``
|
2015-06-18 13:36:51 +00:00
|
|
|
when creating the Tornado application.
|
|
|
|
|
|
|
|
.. literalinclude:: ../examples/tornado-json-logger.py
|