Strict and safe logging SDK.
Project description
Stella Logger
Strict and safe structured logging SDK for Python. Stella Logger centralizes log event definitions, validates payloads with Pydantic 2.x, renders messages from templates (no ad-hoc overrides), and adapts output for multiple clouds via pluggable “output modes.”
- Centralized definitions:
LogDefinition+LogRegistrykeep event keys/codes unique. - Validated payloads: Optional Pydantic models ensure schema correctness.
- Template-based messages: Messages are rendered from
message_template; callers cannot inject arbitrary text. - Cloud-ready output: Standard
loggingbackend with modes for JSON line (CloudWatch), nested extra (GCP), or flat extra (Lambda JSON).
Why
Long-running services accumulate ad-hoc logs that drift. Stella Logger treats logs as events with stable keys/codes, enforceable schemas, and predictable output formats, keeping observability consistent across teams and clouds.
Install
pip install stella-logger
Quickstart
import logging
from pydantic import BaseModel
from stella_logger.core import StellaCoreLogger, StellaCoreSettings, StellaSeverity
from stella_logger.schema import LogDefinition, LogRegistry, LogKind
from stella_logger.logger import StellaLogger
class DbQueryTimeoutPayload(BaseModel):
host: str
port: int
elapsed_ms: int | None = None
definitions = [
LogDefinition(
key="DB_QUERY_TIMEOUT",
numeric=1053,
message_template="DB timeout on {host}:{port}, elapsed={elapsed_ms}ms",
severity=StellaSeverity.ERROR,
kind=LogKind.ERROR,
category="TECH_ERROR",
schema_model=DbQueryTimeoutPayload,
)
]
registry = LogRegistry(definitions)
core = StellaCoreLogger(
settings=StellaCoreSettings(
service_name="my-app",
service_version="1.5.17",
structured_message=True, # JSON_MESSAGE mode
),
base_logger=logging.getLogger("myapp.stella"),
)
logger = StellaLogger(core=core, registry=registry)
logger.log_error("DB_QUERY_TIMEOUT", extra={"host": "db1", "port": 5432, "elapsed_ms": 1200})
Output modes (core)
JSON_MESSAGE:msg=json.dumps(payload); best for AWS CloudWatch Logs (non-Lambda).FLAT_EXTRA:msg=payload["message"]; extra is flattened (message dropped); good for Lambda JSON logging.NESTED_EXTRA:msg=payload["message"]; extra nests payload underpayload_attr_name(e.g.,json_fieldsfor GCP).
Project layout
- SDK code:
src/stella_logger/ - Tests:
tests/ - Docs (design/spec/recipes):
docs/
詳細な設計思想・仕様・クラウド別レシピは docs/ を参照してください。
Development
- Install deps:
poetry install --with dev - Run tests:
poetry run pytest - Lint:
poetry run ruff check
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file stella_logger-1.0.1.tar.gz.
File metadata
- Download URL: stella_logger-1.0.1.tar.gz
- Upload date:
- Size: 7.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e32570895b4eb78bc6b690fa48f1ecb1a8641a19225ccd79877b948e57028245
|
|
| MD5 |
3fa9bafdc7f560c163bab1aa823d8328
|
|
| BLAKE2b-256 |
89e8c3cfd63695235e19ff99a77547a3384705569bf2328887dc6f9b038f2cfa
|
File details
Details for the file stella_logger-1.0.1-py3-none-any.whl.
File metadata
- Download URL: stella_logger-1.0.1-py3-none-any.whl
- Upload date:
- Size: 11.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bdd8474c688db3e2c081e2515261e556bcf1dd484ec65058831c92f431289cea
|
|
| MD5 |
e1967e8fc6837257a7644cbfc11ce2f3
|
|
| BLAKE2b-256 |
2ac38732d38b5a3a36801039fec9838c5a78f95b133e113e3c8256b51408de31
|