Laravel如何设置日志记录到指定文件,并记录任意类型日志?

2026-04-01 07:421阅读0评论SEO教程
  • 内容介绍
  • 文章标签
  • 相关推荐

本文共计174个文字,预计阅读时间需要1分钟。

Laravel如何设置日志记录到指定文件,并记录任意类型日志?

以下是对给定代码的简化

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

实际效果类似于:php使用方式二:us

如下所示:

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

实际效果如下:

Laravel如何设置日志记录到指定文件,并记录任意类型日志?

方式二:

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); }

以上这篇使用laravel指定日志文件记录任意日志就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持易盾网络。

本文共计174个文字,预计阅读时间需要1分钟。

Laravel如何设置日志记录到指定文件,并记录任意类型日志?

以下是对给定代码的简化

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

实际效果类似于:php使用方式二:us

如下所示:

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

实际效果如下:

Laravel如何设置日志记录到指定文件,并记录任意类型日志?

方式二:

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); }

以上这篇使用laravel指定日志文件记录任意日志就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持易盾网络。