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
def configure_logging(*, json_output: bool | None=None) -> NoneConfigure 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
def get_logger(component: str | None=None, **initial_binds: object) -> FilteringBoundLoggerReturn a bound structlog logger, optionally with a component name.
Example::
logger = get_logger("auth") logger.info("login attempt", username="alice")
#init_sentry
def init_sentry(dsn: str, **kwargs: object) -> NoneInitialize 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 tosentry_sdk.init().