Skip to content

dockerflow.logging.JsonLogFormatter doesn't handle extra arguments that are not json-serializable #8

@diox

Description

@diox

Enabling dockerflow.logging.JsonLogFormatter in your project can cause TypeError exceptions when extra, non json-serializable arguments are passed to the logging call.

>>> from logging import getLogger
>>> getLogger('foo').warning('warning with extra info', extra={'something': object()})
Traceback (most recent call last):
(...)
TypeError: <object object at 0x7f5e88a54630> is not JSON serializable

It's a perfect valid logging call, you might have other formatters configured taking advantage of the extra data. Django does that in some of its core, for instance passing request objects when logging 404 or 500 request errors.

I think the best approach here would be to have a custom serializer class that would just use repr() on data it can not serialize.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions