Skip to content

Commit

Permalink
add separate access logger
Browse files Browse the repository at this point in the history
  • Loading branch information
Yrob committed Aug 13, 2024
1 parent b55fed5 commit 071b5e8
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions jwtproxy/src/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,12 @@
"formatter": "json-audit",
"level": "DEBUG",
},
"appinsightsaccess": {
"class": "opencensus.ext.azure.log_exporter.AzureLogHandler",
"connection_string": AZURE_APPLICATIONINSIGHTS_CONNSTRING,
"formatter": "json",
"level": "DEBUG",
},
},
"loggers": {
"jwtproxy.applogs": {
Expand All @@ -62,19 +68,28 @@
"handlers": ["appinsights"],
"level": "DEBUG", # Send everything
},
"jwtproxy.accesslogs": {
"propagate": False,
"handlers": ["appinsightsaccess"],
"level": "DEBUG", # Send everything
},
},
}

if not AZURE_APPLICATIONINSIGHTS_CONNSTRING:
log_cfg["handlers"].pop("appinsights")
log_cfg["handlers"].pop("appinsightsaccess")
log_cfg["loggers"]["jwtproxy.auditlogs"]["handlers"] = [
"console",
]
log_cfg["loggers"]["jwtproxy.accesslogs"]["handlers"] = [
"console",
]
dictConfig(log_cfg)

app_logger = logging.getLogger("jwtproxy.applogs")
audit_logger = logging.getLogger("jwtproxy.auditlogs")

access_logger = logging.getLogger("jwtproxy.accesslogs")

async def fetch_token(req: web.Request):
"""Fetch the token from the request.
Expand Down Expand Up @@ -265,6 +280,6 @@ async def main(*argv):

# support listening on unix domain sockets and ports
if args.path:
web.run_app(main(), host="0.0.0.0", path=args.path, access_log=audit_logger)
web.run_app(main(), host="0.0.0.0", path=args.path, access_log=access_logger)
else:
web.run_app(main(), host="0.0.0.0", port=args.port, access_log=audit_logger)
web.run_app(main(), host="0.0.0.0", port=args.port, access_log=access_logger)

0 comments on commit 071b5e8

Please sign in to comment.