Outputs
Outputs define where captured events are sent. Pass any output class toobserve() via the output parameter.
Stdout
Prints a one-line summary to the terminal after every call.| Best for | Development, debugging |
| Infra required | None |
| Production safe | No |
SQLite
Persists every event to a local SQLite.db file. File is created automatically if it doesn’t exist.
| Best for | Local dev, single-process staging |
| Infra required | None |
| Production safe | Single worker only |
| Multi-worker | Not recommended — use Logger or HTTP |
Logger
Writes structured JSON to Python’s standardlogging module. In production this automatically routes to CloudWatch, Datadog, GCP Logging, Grafana Loki, or whatever log aggregator is already configured. Zero new infra.
| Best for | Production |
| Infra required | None — uses existing log infra |
| Production safe | Yes — multi-worker safe |
| Works with | CloudWatch, Datadog, GCP, Loki, ELK, any log aggregator |
HTTP
POSTs every event as JSON to any HTTP endpoint you control.| Best for | Self-hosted dashboards, custom ingestion |
| Infra required | Your own endpoint |
| Production safe | Yes |
| Failure behaviour | Silent drop — never affects your app |
Multi
Writes to multiple outputs at once.Auto Detection
When no output is specified, TokenSense reads the environment and picks a sensible default:ENV value | Output |
|---|---|
production | Logger("tokensense") |
staging | Multi(Stdout(), SQLite()) |
development | Multi(Stdout(), SQLite()) |
| not set | Multi(Stdout(), SQLite()) |
ENV, ENVIRONMENT, APP_ENV — whichever is set first.
Override at any time by passing output= explicitly.
