Skip to content

Commit 5b757ee

Browse files
committed
feat: add logging configuration based on env variable
- Set up configurable log level using LOG_LEVEL environment variable. - Applied logging settings to uvicorn loggers for consistency.
1 parent f2b3485 commit 5b757ee

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

src/server/main.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
from __future__ import annotations
44

5+
import logging
56
import os
67
import threading
78
from pathlib import Path
@@ -22,6 +23,18 @@
2223
# Load environment variables from .env file
2324
load_dotenv()
2425

26+
# Configure logging based on environment
27+
log_level = os.getenv("LOG_LEVEL", "INFO").upper()
28+
logging.basicConfig(
29+
level=getattr(logging, log_level, logging.INFO),
30+
format="%(asctime)s - %(name)s - %(levelname)s - %(message)s",
31+
handlers=[logging.StreamHandler()],
32+
)
33+
34+
# Set uvicorn loggers to the same level
35+
logging.getLogger("uvicorn").setLevel(getattr(logging, log_level, logging.INFO))
36+
logging.getLogger("uvicorn.access").setLevel(getattr(logging, log_level, logging.INFO))
37+
2538
# Initialize Sentry SDK if enabled
2639
if os.getenv("GITINGEST_SENTRY_ENABLED") is not None:
2740
sentry_dsn = os.getenv("GITINGEST_SENTRY_DSN")

0 commit comments

Comments
 (0)