Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dockerflow.logging.JsonLogFormatter should handle dates better #10

Open
diox opened this issue Apr 6, 2017 · 2 comments
Open

dockerflow.logging.JsonLogFormatter should handle dates better #10

diox opened this issue Apr 6, 2017 · 2 comments

Comments

@diox
Copy link
Contributor

diox commented Apr 6, 2017

#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.

@diox
Copy link
Contributor Author

diox commented Apr 6, 2017

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.

@jezdez
Copy link
Contributor

jezdez commented Apr 6, 2017

@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
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants