litestar-logging
Logging
Execution Workflow
- Choose the logging backend first: stdlib logging, picologging, Structlog, or a custom config subclass.
- Configure logging once at app setup with
logging_configor the Structlog plugin. - Use Litestar's non-blocking
queue_listenerhandler unless a concrete reason requires otherwise. - Decide when exceptions should be logged and which stack traces should be suppressed.
- Standardize request and app logger usage so fields, levels, and redaction rules stay consistent.
- Validate that logs remain actionable without leaking sensitive data.
Core Rules
- Keep logging configuration centralized at app construction.
- Prefer the built-in non-blocking
queue_listenerhandler for async applications. - Treat exception logging policy as an explicit decision; Litestar does not log exceptions by default outside debug mode.
- Use
disable_stack_tracefor expected exception types or status codes that should not spam traces. - Keep secrets, auth material, and sensitive request data out of logs.
- Avoid duplicate logging across middleware, exception handlers, and business code.
- Keep logging concerns separate from metrics and tracing.
Decision Guide
- Use
LoggingConfigfor standard logging or picologging-based setups. - Use
logging_module="picologging"when picologging is the desired backend. - Use
StructlogPluginwhen structured logging with Structlog is the project standard. - Use
log_exceptions="always"when production incidents require exception logs even outside debug mode. - Use
disable_stack_tracefor common expected errors such as404or domain-level validation problems. - Subclass
BaseLoggingConfigonly when the built-in configs cannot express the needed behavior.
Reference Files
Read only the sections you need:
- For stdlib logging, picologging, logger access, and custom config subclassing, read references/configuration-patterns.md.
- For exception logging, stack-trace suppression, Structlog, and redaction-oriented guidance, read references/exception-and-structlog-patterns.md.
Recommended Defaults
- Keep root level, handler choice, and formatter shape explicit.
- Use
request.loggerfor request-scoped logs and one shared app logger for app-level events. - Log exceptions intentionally instead of assuming Litestar will do it for you.
- Suppress traces only for expected, high-volume failures.
- Keep message fields and key names stable for searchability.
Anti-Patterns
- Writing blocking log handlers into async request paths when
queue_listenerwould suffice. - Logging secrets, tokens, or raw sensitive payloads.
- Logging the same failure at multiple layers without adding new context.
- Enabling stack traces for high-volume expected failures that operators already understand.
- Subclassing logging config before exhausting built-in options.
Validation Checklist
- Confirm logging is configured exactly once.
- Confirm request and app loggers emit at the intended levels.
- Confirm
log_exceptionsanddisable_stack_tracematch the incident policy. - Confirm secrets and sensitive request fields are absent or redacted.
- Confirm queue-based handlers or equivalent non-blocking behavior are in place.
- Confirm structured logging output matches downstream log ingestion expectations.
Cross-Skill Handoffs
- Use
litestar-metricsfor quantitative observability and scrape/export concerns. - Use
litestar-exception-handlingfor client-facing error contracts separate from logging behavior. - Use
litestar-debuggingfor incident-driven troubleshooting workflows. - Use
litestar-securitywhen logging policy intersects with secrets, auth context, or redaction requirements.
Litestar References
More from alti3/litestar-skills
litestar-responses
Build Litestar responses with typed return values, explicit Response containers, layered response classes, headers, cookies, status-code control, redirects, files, streams, server-sent events, ASGI app returns, and background tasks. Use when shaping outbound HTTP behavior, correcting response contracts, or choosing the right Litestar response primitive. Do not use for request parsing, validation, or authentication policy design.
22litestar-authentication
Implement Litestar authentication with custom authentication middleware, built-in security backends, JWT and session flows, route inclusion and exclusion rules, and typed auth context on `Request` / `ASGIConnection`. Use when establishing identity, issuing or validating credentials, or attaching authenticated user context in Litestar. Do not use for generic request parsing, broad security audits, or unrelated transport concerns.
22litestar-middleware
Design and apply Litestar middleware for cross-cutting concerns such as CORS, CSRF, allowed-host checks, compression, rate limiting, logging, sessions, request enrichment, policy enforcement, and custom ASGI pipeline control. Use when behavior must wrap broad route sets consistently across the ASGI stack. Do not use for route-specific business rules, simple response mutation better handled by lifecycle hooks, or auth/guard policy work that belongs in security-focused skills.
20litestar-routing
Design and implement Litestar routing with app/router/controller composition, handler decorators, path and parameter modeling, route indexing/reverse lookups, ASGI mounting, and layered route metadata. Use when creating or refactoring endpoint topology and URL contracts. Do not use for purely internal service logic unrelated to HTTP route structure.
18litestar-dto
Configure Litestar DTO behavior for inbound parsing and outbound serialization, including layer-scoped `dto`/`return_dto`, `DTOConfig` policies, `DTOData` update workflows, and custom `AbstractDTO` implementations. Use when API payload contracts differ from internal model structures. Do not use when internal models can be exposed safely without transformation.
18litestar-openapi
Configure Litestar OpenAPI schema generation and documentation UX with `OpenAPIConfig`, route-level schema metadata, schema generation controls, operation customization, UI render plugins, and documentation endpoint strategy. Use when API contract and docs quality must be implemented or corrected, especially for request, auth, and metrics surfaces. Do not use for runtime business logic changes unrelated to schema or documentation.
17