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.
Some early September spring shots from a bushwalk, It is still too early for wildflowers.
I recently needed to clone over a smaller NVMe to a 2TB SK Hynix Platinum…
If you ever needed a simple solution in Laravel to delete an entire directory and…
How to enforce only one user to register or be registered in a Laravel web…