Skip to content

Commit

Permalink
Add own formatter for api_logger
Browse files Browse the repository at this point in the history
  • Loading branch information
mandarvaze committed Aug 3, 2021
2 parents 066afb3 + d4a2576 commit 497ea6e
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions apphelpers/rest/hug.py
@@ -1,6 +1,5 @@
from dataclasses import dataclass, asdict
from falcon import HTTPUnauthorized, HTTPForbidden, HTTPNotFound

import hug
from hug.decorators import wraps

Expand Down Expand Up @@ -33,6 +32,8 @@ def setup_api_logging():
api_logger = logging.getLogger('APILogger')
api_logger.setLevel(level)
handler = SysLogHandler(address=(rsyslog_server, port))
formatter = logging.Formatter('| %(asctime)s | %(message)s')
handler.setFormatter(formatter)
api_logger.addHandler(handler)
else:
print('APILogger not enabled.')
Expand Down Expand Up @@ -169,7 +170,7 @@ def set_context(response, request, context, module):
if api_logger:
# To know why % style is used instead of f-strings,
# search "Use lazy % formatting in logging"
api_logger.info('%s %s | %s | %s', api_logger_tag, uid,
api_logger.info('%s | %s | %s | %s', api_logger_tag, uid,
request.method, request.url)

except InvalidSessionError:
Expand Down

0 comments on commit 497ea6e

Please sign in to comment.