Add configurable logging from settings
This commit is contained in:
parent
435c11b6ca
commit
e925f21762
3 changed files with 14 additions and 0 deletions
34
src/oidc_test/log_conf.yaml
Normal file
34
src/oidc_test/log_conf.yaml
Normal file
|
@ -0,0 +1,34 @@
|
|||
version: 1
|
||||
disable_existing_loggers: False
|
||||
formatters:
|
||||
default:
|
||||
"()": uvicorn.logging.DefaultFormatter
|
||||
format: "%(asctime)s - %(name)s - %(levelname)s - %(message)s"
|
||||
access:
|
||||
"()": uvicorn.logging.AccessFormatter
|
||||
format: "%(asctime)s - %(name)s - %(levelname)s - %(message)s"
|
||||
handlers:
|
||||
default:
|
||||
formatter: default
|
||||
class: logging.StreamHandler
|
||||
stream: ext://sys.stderr
|
||||
access:
|
||||
formatter: access
|
||||
class: logging.StreamHandler
|
||||
stream: ext://sys.stdout
|
||||
loggers:
|
||||
uvicorn.error:
|
||||
level: INFO
|
||||
handlers:
|
||||
- default
|
||||
propagate: no
|
||||
uvicorn.access:
|
||||
level: INFO
|
||||
handlers:
|
||||
- access
|
||||
propagate: no
|
||||
"oidc-test":
|
||||
level: DEBUG
|
||||
handlers:
|
||||
- default
|
||||
propagate: yes
|
|
@ -6,6 +6,9 @@ from typing import Annotated
|
|||
from pathlib import Path
|
||||
from datetime import datetime
|
||||
import logging
|
||||
import logging.config
|
||||
import importlib.resources
|
||||
from yaml import safe_load
|
||||
from urllib.parse import urlencode
|
||||
from contextlib import asynccontextmanager
|
||||
|
||||
|
@ -46,6 +49,16 @@ from oidc_test.resource_server import resource_server
|
|||
|
||||
logger = logging.getLogger("oidc-test")
|
||||
|
||||
if settings.log:
|
||||
assert __package__ is not None
|
||||
with (
|
||||
importlib.resources.path(__package__) as package_path,
|
||||
open(package_path / settings.log_config_file) as f,
|
||||
):
|
||||
logging_config = safe_load(f)
|
||||
logging.config.dictConfig(logging_config)
|
||||
|
||||
breakpoint()
|
||||
templates = Jinja2Templates(Path(__file__).parent / "templates")
|
||||
|
||||
|
||||
|
|
|
@ -104,6 +104,7 @@ class Settings(BaseSettings):
|
|||
auth: AuthSettings = AuthSettings()
|
||||
secret_key: str = "".join(random.choice(string.ascii_letters) for _ in range(16))
|
||||
log: bool = False
|
||||
log_config_file: str = "log_conf.yaml"
|
||||
insecure: Insecure = Insecure()
|
||||
cors_origins: list[str] = []
|
||||
debug_token: bool = False
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue