Skip to content

Commit

Permalink
Merge pull request #17 from communitiesuk/filter-healthcheck
Browse files Browse the repository at this point in the history
BAU: Filter healthcheck from access logs
  • Loading branch information
gidsg authored Aug 24, 2022
2 parents 843ce66 + 2eb549d commit 57c2599
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
21 changes: 21 additions & 0 deletions fsd_utils/gunicorn/config/devtest.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import datetime
import logging
import re

import pytz
from gunicorn.glogging import Logger
Expand Down Expand Up @@ -238,3 +240,22 @@ def worker_int(worker):

def worker_abort(worker):
worker.log.info("worker received SIGABRT signal")


class RequestPathFilter(logging.Filter):
def __init__(self, *args, path_re, **kwargs):
super().__init__(*args, **kwargs)
self.path_filter = re.compile(path_re)

def filter(self, record):
req_path = record.args["U"]
if not self.path_filter.match(req_path):
return True # log this entry
# ... additional conditions can be added here ...
return False # do not log this entry


def on_starting(server):
server.log.access_log.addFilter(
RequestPathFilter(path_re=r"^/healthcheck$")
)
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

setup_kwargs = {
"name": "funding-service-design-utils",
"version": "0.0.14",
"version": "0.0.15",
"description": "Utils for the fsd-tech team",
"long_description": None,
"author": "DLUHC",
Expand Down

0 comments on commit 57c2599

Please sign in to comment.