Skip to main content

Strict and safe logging SDK.

Project description

Stella Logger

License: MIT Python Tests

Strict and safe structured logging SDK for Python. Stella Logger centralizes log event definitions, validates payloads with Pydantic 2.x (schema is required), renders messages from templates (no ad-hoc overrides), and adapts output for multiple clouds via pluggable “output modes.”

  • Centralized definitions: LogDefinition + LogRegistry keep 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 logging backend 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(
        event_key="DB_QUERY_TIMEOUT",
        event_code=1053,
        message_template="DB timeout on {host}:{port}, elapsed={elapsed_ms}ms (code={event_code})",
        event_severity=StellaSeverity.ERROR,
        event_kind=LogKind.ERROR,
        event_category="TECH_ERROR",
        schema_model=DbQueryTimeoutPayload,
        include_message_in_extra=True,
        # include_event_key_in_extra / include_event_code_in_extra /
        # include_severity_in_extra / include_kind_in_extra /
        # include_category_in_extra all default to True and can be set False.
    )
]

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 under payload_attr_name (e.g., json_fields for 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

stella_logger-1.0.2.tar.gz (10.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

stella_logger-1.0.2-py3-none-any.whl (14.2 kB view details)

Uploaded Python 3

File details

Details for the file stella_logger-1.0.2.tar.gz.

File metadata

  • Download URL: stella_logger-1.0.2.tar.gz
  • Upload date:
  • Size: 10.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.11

File hashes

Hashes for stella_logger-1.0.2.tar.gz
Algorithm Hash digest
SHA256 7900c9ab06d1394dbb86b886806da6b6710b3d0fdcd5c071fa16273d95d0a557
MD5 85aeb01dc2ddecb09412c3608dbdb6f3
BLAKE2b-256 89a4ee488ec7e133f4f04c11492a027991b1254e6035b4caa4ff6f1d545a4a7d

See more details on using hashes here.

File details

Details for the file stella_logger-1.0.2-py3-none-any.whl.

File metadata

  • Download URL: stella_logger-1.0.2-py3-none-any.whl
  • Upload date:
  • Size: 14.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.11

File hashes

Hashes for stella_logger-1.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 3a7a251f530b28e4be5c24e0cacce8a537447e8a5bfbbb98bcea674b65be9cfb
MD5 c32db698a25c25792bb7aeab68325584
BLAKE2b-256 5a567df27cb99d573c25e2f7841112f79ffda3a0820de256effc7860a2dd9167

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page