From 102e454902a1a391fe2141e2505a6b296f21e8ea Mon Sep 17 00:00:00 2001 From: cmdr2 Date: Sat, 24 Sep 2022 15:55:45 +0530 Subject: [PATCH] Don't log thumbnail requests into the access log, makes it hard to answer support queries since the server and access logs are the same right now --- ui/server.py | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/ui/server.py b/ui/server.py index b446b2f1..bdb252d8 100644 --- a/ui/server.py +++ b/ui/server.py @@ -30,6 +30,11 @@ model_is_loading = False modifiers_cache = None outpath = os.path.join(os.path.expanduser("~"), OUTPUT_DIRNAME) +# don't show access log entries for URLs that start with the given prefix +ACCESS_LOG_SUPPRESS_PATH_PREFIXES = ['/ping', '/modifier-thumbnails'] + +app.mount('/media', StaticFiles(directory=os.path.join(SD_UI_DIR, 'media/')), name="media") + # defaults from https://huggingface.co/blog/stable_diffusion class ImageRequest(BaseModel): session_id: str = "session" @@ -59,8 +64,6 @@ class ImageRequest(BaseModel): class SetAppConfigRequest(BaseModel): update_branch: str = "main" -app.mount('/media', StaticFiles(directory=os.path.join(SD_UI_DIR, 'media/')), name="media") - @app.get('/') def read_root(): headers = {"Cache-Control": "no-cache, no-store, must-revalidate", "Pragma": "no-cache", "Expires": "0"} @@ -213,12 +216,17 @@ def read_modifiers(): def read_home_dir(): return {outpath} -# don't log /ping requests -class HealthCheckLogFilter(logging.Filter): +# don't log certain requests +class LogSuppressFilter(logging.Filter): def filter(self, record: logging.LogRecord) -> bool: - return record.getMessage().find('/ping') == -1 + path = record.getMessage() + for prefix in ACCESS_LOG_SUPPRESS_PATH_PREFIXES: + if path.find(prefix) != -1: + return False -logging.getLogger('uvicorn.access').addFilter(HealthCheckLogFilter()) + return True + +logging.getLogger('uvicorn.access').addFilter(LogSuppressFilter()) # start the browser ui import webbrowser; webbrowser.open('http://localhost:9000') \ No newline at end of file