Showing posts with label laravel custom log file example. Show all posts
Showing posts with label laravel custom log file example. Show all posts

Laravel Create Custom Log File Example

Laravel Create Custom Log File Example

Hi Guys,

Today,I will learn you how to create custom log file in laravel? This article will give you simple example of laravel custom log file example. it's simple example of create custom log file in laravel. Follow bellow tutorial step of how to make custom log file laravel.

Laravel by default provide storage/logs/laravel.log file location where it will display log file. but sometime you may require to create log file with specific task. for example, if you are working with payment task and you need all logs separately log file for payment, so you can easily find out solution.

Here, i will give you very simple example, so let's see how to add custom channel with new log file location.

config/logging.php
...
'channels' => [
        ...
        'itwebtuts' => [
            'driver' => 'single',
            'path' => storage_path('logs/itwebtuts.log'),
            'level' => 'info',
        ],
....
Route Code:
Route::get('create-custom-log', function () {
    \Log::channel('itwebtuts')->info('This is testing for itwebtuts.com!');
    dd('done');
});
now you can check your own. storage/logs/itwebtuts.log
[2021-04-13 11:46:41] local.INFO: This is testing for itwebtuts.com!  
It will help you....