Skip to content
This repository has been archived by the owner on Sep 12, 2023. It is now read-only.

Commit

Permalink
feat(logging): configurable dependency log levels.
Browse files Browse the repository at this point in the history
  • Loading branch information
peterschutt committed Nov 17, 2022
1 parent c101392 commit a4fda6d
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 3 deletions.
13 changes: 13 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ LOG_OBFUSCATE_HEADERS='["Authorization","X-API-KEY"]'
LOG_REQUEST_FIELDS='["path","method","content_type","headers","cookies","query","path_params","body"]'
LOG_RESPONSE_FIELDS='["status_code","cookies","headers","body"]'
LOG_WORKER_EVENT="Worker"
LOG_SAQ_LEVEL=30
LOG_SQLALCHEMY_LEVEL=30
LOG_UVICORN_ACCESS_LEVEL=30
LOG_UVICORN_ERROR_LEVEL=30

# OpenAPI
OPENAPI_CONTACT_EMAIL=[email protected]
Expand All @@ -42,3 +46,12 @@ REDIS_URL=redis://cache.local:6379/0
# Sentry
SENTRY_DSN=
SENTRY_TRACES_SAMPLE_RATE=0.0001

# Server
SERVER_APP_LOC=app.main:app_factory
SERVER_APP_LOC_IS_FACTORY=true
SERVER_HOST=localhost
SERVER_KEEPALIVE=65
SERVER_PORT=8000
SERVER_RELOAD=false
SERVER_RELOAD_DIRS='[]'
7 changes: 4 additions & 3 deletions src/starlite_saqlalchemy/log/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,21 +114,22 @@ def configure(processors: Sequence[Processor]) -> None:
loggers={
"uvicorn.access": {
"propagate": False,
"level": logging.WARNING,
"level": settings.log.UVICORN_ACCESS_LEVEL,
"handlers": ["queue_listener"],
},
"uvicorn.error": {
"propagate": False,
"level": logging.WARNING,
"level": settings.log.UVICORN_ERROR_LEVEL,
"handlers": ["queue_listener"],
},
"saq": {
"propagate": False,
"level": logging.WARNING,
"level": settings.log.SAQ_LEVEL,
"handlers": ["queue_listener"],
},
"sqlalchemy.engine": {
"propagate": False,
"level": settings.log.SQLALCHEMY_LEVEL,
"handlers": ["queue_listener"],
},
},
Expand Down
15 changes: 15 additions & 0 deletions src/starlite_saqlalchemy/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,14 @@ class Config:
"""Attributes of the [Response][starlite.response.Response] to be logged."""
WORKER_EVENT: str = "Worker"
"""Log event name for logs from SAQ worker."""
SAQ_LEVEL: int = 30
"""Level to log SAQ logs."""
SQLALCHEMY_LEVEL: int = 30
"""Level to log SAQ logs."""
UVICORN_ACCESS_LEVEL: int = 30
"""Level to log uvicorn access logs."""
UVICORN_ERROR_LEVEL: int = 30
"""Level to log uvicorn error logs."""


# noinspection PyUnresolvedReferences
Expand Down Expand Up @@ -222,12 +230,19 @@ class Config:
env_prefix = "SERVER_"

APP_LOC: str = "app.main:create_app"
"""Path to app executable, or factory."""
APP_LOC_IS_FACTORY: bool = True
"""Indicate if APP_LOC points to an executable or factory."""
HOST: str = "localhost"
"""Server network host."""
KEEPALIVE: int = 65
"""Seconds to hold connections open (65 is > AWS lb idle timeout)."""
PORT: int = 8000
"""Server port."""
RELOAD: bool = False
"""Turn on hot reloading."""
RELOAD_DIRS: list[str] = ["src/"]
"""Directories to watch for reloading."""


# `.parse_obj()` thing is a workaround for pyright and pydantic interplay, see:
Expand Down

0 comments on commit a4fda6d

Please sign in to comment.