fastware v0.1.0 /src.fastware.logging
On this page

Structured logging configuration using structlog with automatic JSON output in production and colored console rendering in development mode.

#src.fastware.logging

#src.fastware.logging

Structured logging configuration using structlog with automatic JSON output in production and colored console rendering in development mode.

Provides JSON-formatted log output in production (non-tty) and colored console output in development (tty). Call configure_logging() once at startup.

Usage::

from fastware.logging import configure_logging, get_logger

configure_logging() logger = get_logger(component="auth") logger.info("login attempt", username="alice")

#configure_logging

python
def configure_logging(*, json_output: bool | None=None) -> None

Configure structlog processors and stdlib integration.

Call once at server startup (e.g. in a lifespan handler).

Args:

  • json_output: If True, emit JSON lines. If False, use colored

console output. If None (default), auto-detect based on whether stderr is a TTY.

#get_logger

python
def get_logger(component: str | None=None, **initial_binds: object) -> FilteringBoundLogger

Return a bound structlog logger, optionally with a component name.

Example::

logger = get_logger("auth") logger.info("login attempt", username="alice")

#init_sentry

python
def init_sentry(dsn: str, **kwargs: object) -> None

Initialize Sentry SDK for error tracking (optional dependency).

If sentry-sdk is not installed, this is a no-op. When available, it initializes with ASGI-compatible settings and a before_send filter that drops 4xx HTTPError events (they are expected client errors, not actionable server issues).

Args:

  • dsn: Sentry DSN string.
  • **kwargs: Additional arguments forwarded to sentry_sdk.init().