ItSolutionStuff.com

How to Create Custom Log File in Laravel?

By Hardik Savani • April 16, 2024
Laravel

This example is focused on laravel custom log file name. This article goes in detailed on 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 6, laravel 7, laravel 8, laravel 9, laravel 10 and laravel 11 version.

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. add new key "itsolution" on "channels" array.

config/logging.php

...

'channels' => [

...

'itsolution' => [

'driver' => 'single',

'path' => storage_path('logs/itsolution.log'),

'level' => 'info',

],

....

Route Code:

Route::get('create-custom-log', function () {

\Log::channel('itsolution')->info('This is testing for ItSolutionStuff.com!');

dd('done');

});

now you can check your own.

storage/logs/itsolution.log

[2021-04-13 11:46:41] local.INFO: This is testing for ItSolutionStuff.com!

I hope it can help you...

Tags: Laravel
Hardik Savani

Hardik Savani

I'm a full-stack developer, entrepreneur, and founder of ItSolutionStuff.com. Passionate about PHP, Laravel, JavaScript, and helping developers grow.

📺 Subscribe on YouTube

We Are Recommending You

Laravel Jetstream Login with Username or Email Example

Read Now →

Laravel 8 Firebase Mobile Number (OTP) Authentication Tutorial

Read Now →

Laravel Blade @includeWhen and @includeUnless Example

Read Now →

Laravel Blade Switch Case Statement Example

Read Now →

Laravel 8 Socialite Login with Facebook Account Example

Read Now →

How to display query log in Laravel 7/6?

Read Now →

Laravel 7/6 Socialite Login with Google Gmail Account

Read Now →

How to Clear Log File using Command in Laravel?

Read Now →

Git - How to Find a Deleted File in Commit History?

Read Now →