Get "PHP 8 in a Nuthshell" (Now comes with PHP 8.3)
Amit Merchant

Amit Merchant

A blog on PHP, JavaScript, and more

Pail — A Laravel Package for Tailing Logs

A few days ago I discussed many ways to tail logs in Laravel. And it hasn’t been long since I wrote that article, a new package called Pail has popped up on my radar which is also a Laravel package for tailing logs.

The package was built by Nuno Maduro. It’s a pretty simple package that lets you tail logs in your Laravel application using the artisan pail command. It’s a zero-configuration package which means you don’t have to do anything to get it working. It just works out of the box.

The only prerequisite for this package is that your project should be running on PHP 8.2 or higher. Also, keep in mind that the package is still in the development phase. So, it’s not recommended to use it in production yet.

You can install the package using the composer like so.

composer require laravel/pail:1.x-dev

Note: If you face any issues while installing the package, run composer update and then try again.

Once installed, you can start tailing logs using the following command.

php artisan pail

This will start tailing the logs in your terminal like so.

Laravel Pail

As you can tell, the package shows the log in a pretty sleek-looking way so that it’s easy to distinguish between different log levels. All the logs are color-coded and the error logs are printed on the next line so that it’s easy to spot them.

On top of that, the package also shows contextual information like the authenticated user, the request URL, and the request method.

You can filter the logs by specifying the --filter option like so.

php artisan pail --filter="error"

The package also provides the feasibility of filtering logs based on an authenticated user. You can do so by specifying the --user option like so.

php artisan pail --user=1

This will only show the logs that are related to the user with the ID 1.

Check out the package’s repository → Pail

Learn the fundamentals of PHP 8 (including 8.1, 8.2, and 8.3), the latest version of PHP, and how to use it today with my new book PHP 8 in a Nutshell. It's a no-fluff and easy-to-digest guide to the latest features and nitty-gritty details of PHP 8. So, if you're looking for a quick and easy way to PHP 8, this is the book for you.

Like this article? Consider leaving a

Tip

👋 Hi there! I'm Amit. I write articles about all things web development. You can become a sponsor on my blog to help me continue my writing journey and get your brand in front of thousands of eyes.

Comments?