Skip to content

dockerflow.logging.JsonLogFormatter should handle dates better #10

Open

Description

@diox

#8 fixes the exception that can happen when you log objects. What'd be even nicer, as @jezdez pointed out, would be to handle datetimes/dates : currently they are serialized as "datetime.datetime(2017, 4, 6, 9, 27, 7, 479427)" because that's the repr() for a datetime object, but we could do better by using DjangoJSONEncoder, which knows how to handle those objects and more.

Something like this should work, to test:

class SafeJSONEncoder(json.JSONEncoder):
    def default(self, o):
        return repr(o)

class SafeDjangoJSONEncoder(DjangoJSONEncoder, SafeJSONEncoder):
    pass

Then use cls=SafeDjangoJSONEncoder when doing the json.dumps.

Activity

  1. diox commented on Apr 6, 2017

    @diox
    ContributorAuthor

    One problem with that approach: at the moment src/dockerflow/logging.py is generic, does not depend on django. Not sure how to refactor that in a clean way.

  2. jezdez commented on Apr 6, 2017

    @jezdez
    Contributor

    @diox Oh, we'd have to ship an own encoder, literally just copy/pasting from Django. I think I've seen similar encoders in non-Django projects, so no huge problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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