Skip to content

Instantly share code, notes, and snippets.

@gchait
Created December 13, 2025 12:40
Show Gist options
  • Select an option

  • Save gchait/be63ca62e3e88ed093acb2e7ab3ffe15 to your computer and use it in GitHub Desktop.

Select an option

Save gchait/be63ca62e3e88ed093acb2e7ab3ffe15 to your computer and use it in GitHub Desktop.
Hide an endpoint from Uvicorn access logs
class EndpointFilter(Filter):
"""A generic way to filter out web endpoints from the logs."""
# pylint: disable=too-few-public-methods
def __init__(
self,
path: str,
*args,
**kwargs,
):
super().__init__(*args, **kwargs)
self._path = path
def filter(self, record: LogRecord) -> bool:
return record.getMessage().find(self._path) == -1
# Tap into the default uvicorn log stream and manipulate it
logger = getLogger("uvicorn")
uvicorn_access_logger = getLogger("uvicorn.access")
uvicorn_access_logger.addFilter(EndpointFilter(path=HEALTHCHECK_URI))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment