Stream logs to local volume

I hope someone else has a proper solution, but until then here are some quick & dirty workarounds:

A. Change your app’s startup command to ORIG_CMD 2>&1 | tee -a /path/to/log. (Edit: where /path/to/log is a path on a mounted volume.)
Disadvantages: You’ll only get the messages your app writes to stdout/stderr, not the messages generated by Fly. And you won’t get timestamps (but see ts from moreutils). *Edit: demo below.

B. Install flyctl inside your VM and run fly logs (filtered by the current instance to avoid duplicating the logs from other instances). Edit: clarification below.
Disadvantages: Hacky. Need to install flyctl and make your Fly access token available to the VM.

C. Run Fly Log Shipper with a custom file sink (as a separate app with a separate volume; or you could install & run Vector in your app; or implement the HTTP provider endpoint in your app and point the Fly Log Shipper at it).

Edit: See also Local Logging Setup, suggested by @ignoramous below. Note that it uses Loki as the datastore rather than a plain text file.

1 Like