diff --git a/workers/logrotateworker.py b/workers/logrotateworker.py index ddf4f9ad0..e8486403c 100644 --- a/workers/logrotateworker.py +++ b/workers/logrotateworker.py @@ -106,13 +106,24 @@ class LogRotateWorker(Worker): def log_dict(log): """ Pretty prints a LogEntry in JSON. """ - return {'kind_id': log.kind_id, - 'account_id': log.account_id, - 'performer_id': log.performer_id, - 'repository_id': log.repository_id, - 'datetime': str(log.datetime), - 'ip': str(log.ip), - 'metadata_json': json.loads(str(log.metadata_json))} + try: + metadata_json = json.loads(str(log.metadata_json)) + except ValueError: + logger.exception('Could not parse metadata JSON for log entry %s', log.id) + metadata_json = {'__raw': log.metadata_json} + except TypeError: + logger.exception('Could not parse metadata JSON for log entry %s', log.id) + metadata_json = {'__raw': log.metadata_json} + + return { + 'kind_id': log.kind_id, + 'account_id': log.account_id, + 'performer_id': log.performer_id, + 'repository_id': log.repository_id, + 'datetime': str(log.datetime), + 'ip': str(log.ip), + 'metadata_json': metadata_json, + } def main():