This repository has been archived on 2020-03-24. You can view files and clone it, but cannot push or open issues or pull requests.
quay/data/logs_model/logs_producer/util.py
2019-11-12 11:09:47 -05:00

15 lines
539 B
Python

import json
from datetime import datetime
class LogEntryJSONEncoder(json.JSONEncoder):
""" JSON encoder to encode datetimes to ISO8601 format. """
def default(self, obj):
if isinstance(obj, datetime):
return obj.isoformat()
return super(LogEntryJSONEncoder, self).default(obj)
def logs_json_serializer(logentry, sort_keys=False):
""" Serializes a LogEntry to json bytes. """
return json.dumps(logentry.to_dict(), cls=LogEntryJSONEncoder,
ensure_ascii=True, sort_keys=sort_keys).encode('ascii')