diff --git a/.env.example b/.env.example index 0dc4d357..892f7cf6 100644 --- a/.env.example +++ b/.env.example @@ -1,7 +1,7 @@ # App BUILD_NUMBER= DEBUG=true -ENVIRONMENT= +ENVIRONMENT=local NAME=my-starlite-app # API diff --git a/docs/config.md b/docs/config.md index 6e845d9d..95a5a51b 100644 --- a/docs/config.md +++ b/docs/config.md @@ -14,6 +14,16 @@ OPENAPI_VERSION=1.0.0 REDIS_URL=redis://localhost:6379/0 ``` +## Local Development + +Structured logs are nice when sending our logs through to some ingestion service, however, not so +nice for local development. + +set `ENVIRONMENT=local` in your local `.env` file for a nicer local development experience +(we implement +[this structlog pattern](https://www.structlog.org/en/stable/logging-best-practices.html#pretty-printing-vs-structured-output) +for you!). + ## Full `.env` ```dotenv title="Example .env" diff --git a/src/starlite_saqlalchemy/log/__init__.py b/src/starlite_saqlalchemy/log/__init__.py index 83d204cd..8b7c09ef 100644 --- a/src/starlite_saqlalchemy/log/__init__.py +++ b/src/starlite_saqlalchemy/log/__init__.py @@ -3,7 +3,6 @@ from __future__ import annotations import logging -import sys from typing import TYPE_CHECKING import msgspec @@ -35,7 +34,7 @@ structlog.processors.TimeStamper(fmt="iso", utc=True), ] -if sys.stderr.isatty() or "pytest" in sys.modules: # pragma: no cover +if settings.app.ENVIRONMENT == "local": LoggerFactory: Any = structlog.WriteLoggerFactory default_processors.extend([structlog.dev.ConsoleRenderer()]) else: # pragma: no cover diff --git a/tests.env b/tests.env index 92ac9e78..774c73dd 100644 --- a/tests.env +++ b/tests.env @@ -1,7 +1,7 @@ # App BUILD_NUMBER= DEBUG=true -ENVIRONMENT= +ENVIRONMENT=test NAME=my-starlite-app # API