In this episode, we're taking a look at a handy new feature in Laravel: the log()
helper function! We start by setting up Laravel Pale using Composer so we can trail our logs in real time with php artisan pale
. Then, we jump right into the difference between the traditional way of logging (using the Log
facade and methods like info
) and this new helper.
A quick heads up: since PHP has a built-in log()
function (for logarithms), we check out how Laravel deals with naming conflicts by importing its custom log helper from the Illuminate\Support\helpers.php
file.
Once everything's set up, we'll use the new log()
function to write debug messages and even attach some extra context, like dumping out a user as an array. You'll see the logs show up instantly in both the console and the Laravel log files. While this helper defaults to debug-level logs, you can still pass context arrays if needed.
All in all, it's a small but super convenient addition for cleaner, more straightforward logging in your Laravel projects—especially if you find yourself logging a lot during development.