Skip to content

Latest commit

 

History

History
32 lines (25 loc) · 1.23 KB

examples.rst

File metadata and controls

32 lines (25 loc) · 1.23 KB

Examples

Simple Usage

The following snippet uses sprockets.logging.ContextFilter to insert context information into a message using a logging.LoggerAdapter instance.

../examples/simple.py

Dictionary-based Configuration

This package begins to shine if you use the dictionary-based logging configuration offered by logging.config.dictConfig. You can insert the custom filter and format string into the logging infrastructure and insert context easily with logging.LoggerAdapter.

../examples/tornado-app.py

Tornado Application JSON Logging

If you're looking to log Tornado requests as JSON, the sprockets.logging.JSONRequestFormatter class works in conjunction with the tornado_log_function method to output all Tornado log entries as JSON objects. In the following example, the dictionary-based configuration is expanded upon to include specify the sprockets.logging.JSONRequestFormatter as the formatter and passes tornado_log_function in as the log_function when creating the Tornado application.

../examples/tornado-json-logger.py