laravel 5.2 custom log file for different tasks

后端 未结 10 1033
再見小時候
再見小時候 2021-01-30 00:36

Can we create a custom log file for different purposes in laravel 5.2 like for order related log entries that should be in order.log and for payment related stuff the entry shou

10条回答
  •  臣服心动
    2021-01-30 00:53

    Solution:
    
    step1: create a channel inside config/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 dynamic path from the controller  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 :)
    

提交回复
热议问题