Laravel 6 Debug and Logging

Laravel debugging is configured in the file config/logging.php, where there are several Channels supported by Laravel.

In there, it will state the file and its folder location to log messages. By default, all logs go to logs/laravel.log.

The logging levels support RFC 5424;

  • emergency
  • alert
  • critical
  • error
  • warning
  • notice
  • info
  • debug

Here are the basic steps log your debugging information.

Step 1:

In the PHP file, add at the top;

use Illuminate\Support\Facades\Log;

Step 2:

Identify where in the function you wish to do the logging, and add the command to log your information.The example below is loggin to level info

Log::info('This is where my code is activated');

Alternatively, logging can be specified to a specific Channel; E.g. logging to the channel "slack".

Log::channel('slack')->info('This is where my code is activated');


Format the information

Log::debug('This is where my code is activated', ['user'=>99, 'button' => 'edit']);

A detailed formatting of logging information can be done in config/logging.php along with HTMLFormatter class, such as MonologFormatterHTMLFormatter.


Logging to multiple channels

In situations where logging requires the use of 2 or more channels, declare the channels in an array. E.g.

Log::stack(['single','slack'])->info('This is where my code is activated');




No comments:

Blog Archive