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

Commit

Permalink
feat!: "local" environment
Browse files Browse the repository at this point in the history
No auto-detection of local development env, rely on explicit
`ENVIRONMENT=local` flag to setup development optimised logging.

Closes #167
  • Loading branch information
peterschutt committed Dec 14, 2022
1 parent 50bb489 commit 2a439e7
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .env.example
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# App
BUILD_NUMBER=
DEBUG=true
ENVIRONMENT=
ENVIRONMENT=local
NAME=my-starlite-app

# API
Expand Down
10 changes: 10 additions & 0 deletions docs/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
3 changes: 1 addition & 2 deletions src/starlite_saqlalchemy/log/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
from __future__ import annotations

import logging
import sys
from typing import TYPE_CHECKING

import msgspec
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion tests.env
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# App
BUILD_NUMBER=
DEBUG=true
ENVIRONMENT=
ENVIRONMENT=test
NAME=my-starlite-app

# API
Expand Down

0 comments on commit 2a439e7

Please sign in to comment.