Merge pull request #3245 from quay/log-archive-json-bug
Handle the case where the log metadata JSON cannot be parsed
This commit is contained in:
commit
995ba4fd75
1 changed files with 18 additions and 7 deletions
|
@ -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():
|
||||
|
|
Reference in a new issue