Laravel Create Custom Log File Tutorial


Share:
Published By: Admin, Published On: Jun 03, 2021, Category: Laravel 8 Laravel

Hi Guys,

Today, i will explain you how to integrate custom own log file in laravel. in this article i will discuss how to create custom log file in laravel.

In this laravel provide a own log file located inside the storage/logs/laravel.log in which file show a log data.but sometimes a create your own log file, so in this post i will help you how to create a own log file in laravel.

Here, i will give you a simple example of log file first of all how to integrate custom channel with new log file location.

So let's start to the example and follow to the my all step.

Path : config/logging.php
...
'channels' => [
    ...
    'mywebtuts' => [
        'driver' => 'single',
        'path' => storage_path('logs/mywebtuts.log'),
        'level' => 'info',
    ],
....

In your web.php file

Path : routes/web.php
Route::get('custom-log',function(){

    \Log::channel('mywebtuts')->info('This is Testing From My Side.');
    dd('Done');
    
});

now you can check for this code.

Path : storage/logs/mywebtuts.log
[2021-06-03 05:27:50] local.INFO: This is Testing From My Side.  

It will help you...

Share: