Skip to content

Commit

Permalink
Fixed logging
Browse files Browse the repository at this point in the history
  • Loading branch information
kroman0 committed Jan 21, 2015
1 parent f355f13 commit df332d4
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions src/openprocurement/api/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,13 @@ def error_handler(errors):
for i in LOGGER.handlers:
if isinstance(i, JournalHandler):
i._extra['ERROR_STATUS'] = errors.status
if 'ROLE' not in i._extra:
i._extra['ROLE'] = str(errors.request.authenticated_role)
if errors.request.params and 'PARAMS' not in i._extra:
i._extra['PARAMS'] = str(dict(errors.request.params))
if errors.request.matchdict:
for x, j in errors.request.matchdict.items():
i._extra[x.upper()] = j
LOGGER.info('Error on processing request "{}"'.format(dumps(errors, indent=4)), extra={'MESSAGE_ID': 'error_handler'})
for i in LOGGER.handlers:
LOGGER.removeHandler(i)
Expand Down Expand Up @@ -234,20 +241,21 @@ def set_journal_handler(event):
'TENDER_ID': '',
'TIMESTAMP': get_now().isoformat(),
}
if request.params:
params['PARAMS'] = str(dict(request.params))
if request.matchdict:
for i, j in request.matchdict.items():
params[i.upper()] = j
for i in LOGGER.handlers:
LOGGER.removeHandler(i)
LOGGER.addHandler(JournalHandler(**params))


def update_journal_handler_role(event):
request = event.request
for i in LOGGER.handlers:
if isinstance(i, JournalHandler):
i._extra['ROLE'] = str(event.request.authenticated_role)
i._extra['ROLE'] = str(request.authenticated_role)
if request.params:
params['PARAMS'] = str(dict(request.params))
if request.matchdict:
for i, j in request.matchdict.items():
params[i.upper()] = j


def cleanup_journal_handler(event):
Expand Down

0 comments on commit df332d4

Please sign in to comment.