Skip to content

Commit 194b886

Browse files
committed
fix logging impl to load environment variable properly
1 parent 8e5ca64 commit 194b886

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

template_fastapi/settings/logging.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,29 @@
22

33
import logging
44
import logging.config
5+
from functools import lru_cache
56
from typing import Any
67

78
from pydantic import Field
8-
from pydantic_settings import BaseSettings
9+
from pydantic_settings import BaseSettings, SettingsConfigDict
910

1011

11-
class LoggingSettings(BaseSettings):
12+
class Settings(BaseSettings):
1213
"""Logging configuration settings."""
1314

1415
log_level: str = Field(default="INFO", description="Log level (DEBUG, INFO, WARNING, ERROR, CRITICAL)")
1516

16-
class Config:
17-
env_prefix = "" # No prefix, so we can use LOG_LEVEL directly
17+
model_config = SettingsConfigDict(
18+
env_file=".env",
19+
env_ignore_empty=True,
20+
extra="ignore",
21+
)
1822

1923

20-
def get_logging_settings() -> LoggingSettings:
24+
@lru_cache
25+
def get_logging_settings() -> Settings:
2126
"""Get logging settings."""
22-
return LoggingSettings()
27+
return Settings()
2328

2429

2530
def configure_logging() -> None:

0 commit comments

Comments
 (0)