Laravel Create Custom Log File Example

Laravel Create Custom Log File Example

In this example we will show laravel create custom log file example. In this post you will learn how to create custom log file in laravel. I explain simple example of laravel custom log file example. Follow bellow example 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 need 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.

Read Also :  Laravel 8 Send Mail using Mailgun Example

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' => [
        ...
        'webtuts' => [
            'driver' => 'single',
            'path' => storage_path('logs/webtuts.log'),
            'level' => 'info',
        ],
....

Create Route 

Route::get('create-custom-log', function () {
  
    \Log::channel('webtuts')->info('This is testing for web-tuts.com!');
    dd('done');
     
});

Now you can check your own application path such as : storage/logs/webtuts.log

Read Also :  Laravel 8 Soft Delete Example

I hope you understand of laravel custom log file example and it can help you…