今天小编就为大家分享一篇使用laravel指定日志文件记录任意日志,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧

如下所示:

(new Logger('邮件发送失败'))
->pushHandler(new RotatingFileHandler(storage_path('logs/email_send.log')))
->info(json_encode([
'data' => $notifiable,
'error' => $e->getMessage()
],320));

实际效果如下:

方式二:

use Log;
...
 
public function testLog()
{
 $customer_id = 111;
 $code = 333;
 Log::getMonolog()->popHandler();
 Log::useFiles(storage_path('logs/data_info_market.log'), 'info');
 Log::info('==>id=' . $customer_id . ',code=' . $code);
}