Skip to content

Commit

Permalink
Filter out /ping logs
Browse files Browse the repository at this point in the history
  • Loading branch information
Wrench56 committed Jul 8, 2024
1 parent 7532410 commit 4fbd52c
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/backend/server/endpoint_filter.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from typing import Any

import logging


# Source: https://github.com/encode/starlette/issues/864
class EndpointFilter(logging.Filter):
def __init__(
self,
path: str,
*args: Any,
**kwargs: Any,
):
super().__init__(*args, **kwargs)
self._path = path

def filter(self, record: logging.LogRecord) -> bool:
return record.getMessage().find(self._path) == -1
5 changes: 5 additions & 0 deletions src/backend/server/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,18 @@
from db import users
from plugins import downloader, handler
from server import build
from server.endpoint_filter import EndpointFilter
from utils import config, const, motd, settings, status

database = users.Database()

app = FastAPI()
app.mount('/assets', StaticFiles(directory='../public/assets'), name='static')

# Ignore /ping logs
uvicorn_logger = logging.getLogger('uvicorn.access')
uvicorn_logger.addFilter(EndpointFilter(path='/ping'))


@app.get('/favicon.png', include_in_schema=False)
@app.get('/favicon.ico', include_in_schema=False)
Expand Down

0 comments on commit 4fbd52c

Please sign in to comment.