Tailing multiple Laravel logs with Envoy

December 12th, 2022

When you have deployed your Laravel application across multiple servers, for example when running multiple workers, you can run into a situation where you need to quickly tail the log to see what is going on.

Of course you could (and should) use a log aggregation service to handle this for you, but if you just quickly need a glance at what is happening, Laravel Envoy can help you.

You can define a task in your Envoy.php file that looks like the one below. Note that this one contains the current date, if you have the single log channel instead of daily, you can just use laravel.log.

The || true at the end of the statement, is to ensure no error is thrown if the log file does not exist.

$servers = [
    '[email protected]',
    '[email protected]'
];

@task('log', ['on' => $servers, 'parallel' => true])
tail -f /home/forge/example.com/storage/logs/laravel-{{ date('Y-m-d') }}.log || true
@endtask

Which you can then run using:

envoy run log

Envoy will then SSH into the different servers for you in parallel and start tailing the log. With a different colour output for each server.

MENU