Creating and using a custom log file in Laravel, this can help you have a more direct approach to debugging and understanding you application
Open the config/logging.php file and in the channels array add in your new log and its settings.
'channels' => [
'logins' => [
'driver' => 'single',
'path' => storage_path('logs/logins.log'),
'level' => 'debug'
],
] This custom logger is going to be called “logins” (channel name) and its driver being “single” means one filepath (file).
Now to write logs to this log file:
\Log::channel('logins')->info("User {$user->username} logged in"); Output in logs/logins.log:
[2023-04-07 22:36:58] local.INFO: User chief logged in
There 8 different logging levels as per the RFC 5424 specification:
These are ordered from most severe to less severe, as the custom log file created above has its base level as debug it can receive all these log message types.
An example for critical level:
\Log::channel('logins')->critical("This is a critical log!");
A drained and empty Kennington reservoir images from a drone in early July 2024. The…
Merrimu Reservoir from drone. Click images to view larger.
Using FTP and PHP to get an array of file details such as size and…
Creating and using Laravel form requests to create cleaner code, separation and reusability for your…
Improving the default Laravel login and register views in such a simple manner but making…
Laravel validation for checking if a field value exists in the database. The validation rule…