Skip to content

Commit

Permalink
feat: add log-level
Browse files Browse the repository at this point in the history
  • Loading branch information
t03i committed Nov 11, 2024
1 parent b54c42b commit c78c125
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
9 changes: 8 additions & 1 deletion backend/app/core/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

from typing import Annotated, Any, Literal
from pathlib import Path
import logging
from pydantic import (
AnyUrl,
BeforeValidator,
Expand Down Expand Up @@ -33,8 +34,15 @@ class Settings(BaseSettings):
MIN_PROTEIN_LENGTH: int = 16
MAX_PROTEIN_LENGTH: int = 5500

LOG_LEVEL: Literal["DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL"] = "INFO"

@property
@computed_field # type: ignore[prop-decorator]
def log_level(self) -> int:
return getattr(logging, self.LOG_LEVEL)

@property
@computed_field # type: ignore[prop-decorator]
def server_host(self) -> str:
# Use HTTPS for anything other than local development
if self.ENVIRONMENT == "local":
Expand All @@ -52,7 +60,6 @@ def server_host(self) -> str:
SQLITE_DATABASE_PATH: FilePath = Path("data/tmvis.db")
SHARED_DIR_PATH: DirectoryPath = Path("shared/")

@computed_field # type: ignore[prop-decorator]
@property
def SQL_ALCHEMY_DB_URL(self) -> Annotated[str, AnyUrl]:
return f"sqlite:///{self.SQLITE_DATABASE_PATH}"
Expand Down
4 changes: 4 additions & 0 deletions backend/app/main.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import logging

import sentry_sdk
from fastapi import FastAPI
from fastapi.routing import APIRoute
Expand All @@ -20,6 +22,8 @@ def custom_generate_unique_id(route: APIRoute):
},
)

logging.getLogger("uvicorn.access").setLevel(level=logging.WARNING)
logging.getLogger("uvicorn.error").setLevel(level=logging.WARNING)
app = FastAPI(
title=settings.PROJECT_NAME,
openapi_url=f"{settings.API_V1_STR}/openapi.json",
Expand Down

0 comments on commit c78c125

Please sign in to comment.