DWQA QuestionsHow to create dyanamic log file in laravel?
kundan asked 3 years ago

Solution:

step1: create channel inside cconfig/logging.php file
example :
‘channels’ => [
    ‘single’ => [
    ‘driver’ => ‘single’, 
    ‘path’ => storage_path(‘logs/laravel.log’),
    ‘level’ => ‘debug’,
],
‘web’ => [
      ‘driver’ => ‘single’,
      ‘path’ => storage_path(‘logs/web/web.log’),
   ],
] Step2: Now set dyanamic path like this
config([‘logging.channels.web.path’ => storage_path(‘logs/web/’.time().’.log’)]);
Step3 : now generate your log
  Log::channel(‘web’)->info(“your message goes here”);

Enjoy 🙂