Console Access
To interact with your Laravel application in Fly.io, you can ssh into a running instance through theFly SSH Console:
Logs
Hopefully you have configured some neat, helpful logs to keep track of the events happening in your Laravel application. So another way to inspect what your application’s been up to, is to check its application logs. There are several options:Fly.io’s logging service
By default, Fly.io updates Laravel’s logging channel to"stderr" through the [env] configuration found in fly.toml:
"stderr" configuration prints your application logs into the console, where the Fly.io service is able to listen and capture logs from.
In order to view your logs captured by the Fly.io service, you can either:
-
Visit your application’s monitoring section from your Fly.io dashboard like so:
"https://fly.io/apps/<app-name>/monitoring" -
Or run the flyctl logs command:
Take note however that Fly.io logs are kept only for 2 days, before they’re all wiped out!
Volumed Log File
Laravel Log File
If you would like to persist your application logs for a longer duration, you can instead opt to save the logs in a log file by configuring"single", "daily", or "stack" as the LOG_CHANNEL.
So update your fly.toml:
"stack" as your LOG_CHANNEL make sure its channels configuration found in config/logging.php includes "single" or "daily":
"stderr" in the stack’s channels list to view your logs through Fly.io.
Then, through the Fly SSH Console, you can access the logs in your application!
Adding Volume
Deployment wipes out all log files! In order to persist your Laravel log files, you’ll need to add a volume to persist your log folder’s state.-
First let’s create a Volume:
- You can replace the volume name
my_log_volwith any name of your preference. - You can specify your region code through the —region attribute
- You can specify your volume’s size in GB through the —size attribute
- You can replace the volume name
-
Revise
fly.tomlto mount that volume in your/var/www/html/storage/logsfolder: -
Finally, deploy the changes!
Hopefully now, regardless of how many more deployments you make from here, your logs will persist!