From 6db9d9ccd462fdf6bb384fad802c2ebbc83b87ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Gruszczy=C5=84ski?= Date: Mon, 6 Oct 2025 09:00:00 +0200 Subject: [PATCH] logowanie dla health --- app/logging_filter.py | 5 ++--- docker-compose.yml | 6 +++--- logging.yml | 13 +++++++------ 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/app/logging_filter.py b/app/logging_filter.py index 19d3d9f..4c72138 100644 --- a/app/logging_filter.py +++ b/app/logging_filter.py @@ -1,6 +1,5 @@ import logging - class IgnoreHealth(logging.Filter): + def __init__(self, name: str = ""): super().__init__(name) def filter(self, record: logging.LogRecord) -> bool: - msg = record.getMessage() - return "/health" not in msg + return "/health" not in record.getMessage() diff --git a/docker-compose.yml b/docker-compose.yml index 1c77b16..29f0d57 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -4,14 +4,14 @@ services: container_name: ip-geo-api restart: unless-stopped ports: - - "${PORT:-8080}:8000" + - "${PORT:-8080}:${PORT}" healthcheck: test: [ "CMD", "python", "-c", - "import urllib.request; import sys; req = urllib.request.Request('http://localhost:8000/health'); sys.exit(0) if urllib.request.urlopen(req).read() == b'OK' else sys.exit(1)", + "import urllib.request; import sys; req = urllib.request.Request('http://localhost:${PORT}/health'); sys.exit(0) if urllib.request.urlopen(req).read() == b'OK' else sys.exit(1)", ] interval: 30s timeout: 10s @@ -24,7 +24,7 @@ services: "--host", "0.0.0.0", "--port", - "8000", + "${PORT}", "--log-config", "logging.yml", ] diff --git a/logging.yml b/logging.yml index 6da307e..575665c 100644 --- a/logging.yml +++ b/logging.yml @@ -6,21 +6,22 @@ filters: "()": app.logging_filter.IgnoreHealth formatters: - access: - format: '%(levelprefix)s %(client_addr)s - "%(request_line)s" %(status_code)s' - use_colors: true default: + "()": uvicorn.logging.DefaultFormatter format: "%(levelprefix)s %(message)s" use_colors: true + access: + "()": uvicorn.logging.AccessFormatter + format: '%(client_addr)s - "%(request_line)s" %(status_code)s' handlers: + default: + class: logging.StreamHandler + formatter: default access: class: logging.StreamHandler formatter: access filters: [ignore_health] - default: - class: logging.StreamHandler - formatter: default loggers: uvicorn: