Skip to content
A collection of structlog processors for prettier output: a code syntax highlighter, JSON and XML prettifiers, a multiline string printer, and a numeric value rounder.
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
structlog_pretty
test
.coafile Add static analysis Nov 20, 2016
.gitignore Initial commit Nov 18, 2016
.pylintrc Add static analysis Nov 20, 2016
CHANGELOG.md
LICENSE
MANIFEST.in Write proper README file Nov 20, 2016
README.rst
circle.yml circle.yml: Add coverage as a dependency for codecov Nov 20, 2016
fast-requirements.txt
requirements.txt Extract required packages into txt files Nov 19, 2016
setup.cfg
setup.py Bump version to 0.1.1 Dec 15, 2016
test-requirements.txt
tox.ini tox.ini: Run tests on Python 3.4 as well Nov 20, 2016

README.rst

structlog-pretty

CI Status Code Coverage

A collection of structlog processors for prettier output: a code syntax highlighter, JSON and XML prettifiers, a multiline string printer, and a numeric value rounder.

Installation

First of all, sorry, grandma, but structlog-pretty requires Python 3.

You can just install the library with pip:

pip install structlog-pretty

or, if you want faster prettifying processors:

pip install structlog-pretty[fast]

The downside of the faster processors is that they will build C extensions and they need libxml to be installed.

Usage

Add structlog-pretty processors to your structlog configuration

import structlog
import structlog_pretty

structlog.configure(
    # ...
    processors=[
        structlog.stdlib.add_log_level,
        structlog_pretty.NumericRounder(digits=2, only_fields=['timing'])
        structlog.processors.JSONRenderer(),
    ],
)

A nice example of a processor pipeline for the prettiest logs could be

processors=[
    # ...
    structlog_pretty.JSONPrettifier(['request', 'response']),
    structlog_pretty.XMLPrettifier(['soap_response']),
    structlog_pretty.SyntaxHighlighter({'request': 'json', 'response': 'json', 'soap_response': 'xml'}),
    structlog_pretty.MultilinePrinter(['request', 'response', 'soap_response']),
    # ...
],
You can’t perform that action at this time.