A real-time log streaming application that connects to Fly.io's NATS infrastructure to stream application logs via Server-Sent Events (SSE).
The application establishes a persistent connection to Fly.io's NATS server at [fdaa::3]:4223
using the organization credentials.
- Client connects to
/api/logs
endpoint - Server establishes NATS subscription based on environment configuration
- Real-time logs are streamed via Server-Sent Events (SSE)
- Automatic cleanup when client disconnects
Variable | Description | Example |
---|---|---|
FLY_ORG |
Your Fly.io organization name | my-org |
ACCESS_TOKEN |
Fly.io access token for NATS authentication | fm2_xxx... |
Variable | Description | Default Behavior |
---|---|---|
FLY_APP |
Specific app to monitor | If not set, falls back to FLY_APP_NAME |
FLY_APP_NAME |
Reserved runtime variable automatically set by Fly.io | Always set - app streams its own logs by default |
FLY_APP="*"
- Explicitly stream logs from all applications in the organization- Default behavior - Since
FLY_APP_NAME
is always set by Fly.io, the app streams its own logs by default
The application subscribes to different NATS subjects based on configuration:
FLY_APP="*" → logs.> (all apps in org)
FLY_APP="myapp" → logs.myapp.> (specific app)
FLY_APP_NAME="myapp" → logs.myapp.> (default: own app logs)
Streams real-time logs via Server-Sent Events.
Response Format:
{
"message": "log line content",
"timestamp": 1234567890,
"type": "log|system|error",
"persistent": false
}
Connection Events:
- Initial connection confirmation
- Real-time log messages
- Error notifications
- Automatic cleanup on disconnect
Note: The application is designed to run on Fly.io with automatic environment variable injection. The
FLY_APP_NAME
variable is a reserved runtime variable that's always set by Fly.io on each machine, meaning the app will stream its own logs by default unlessFLY_APP
is explicitly configured.
Launch the app from the GitHub repository:
fly launch --from https://github.com/fly-apps/natstream/ \
--yes \
--copy-config \
--org $ORG \
--env FLY_ORG=$ORG \
--no-deploy \
--secrets ACCESS_TOKEN="$(fly tokens create readonly $ORG)" \
--flycast