在laravel 5.6文档中,它表示在创建日志时可以使用与默认值不同的驱动程序
Creating Monolog Handler Channels
所以我在config / logging.php文件中尝试了以下内容
'channels' => [
'stack' => [
'driver' => 'stack',
'channels' => ['masterLog', 'daily'],
],
'email' => [
'driver' => 'monolog',
'handler' => Monolog\Handler\SwiftMailerHandler::class,
'with' => [
'mailer' => Mail::to('[email protected]')->send(new App\Mail\TestMail()),
],
'level' => 'debug',
],
我用处理程序Monolog \ Handler \ SwiftMailerHandler :: class创建了我自己的电子邮件通道,我注意到类构造函数重新编写了一个邮件程序对象,所以我试试这个
Mail :: to('[email protected]') - > send(new App \ Mail \ TestMail())
但是我收到以下错误
RuntimeException尚未设置外观根。
我正是通过这种方式测试错误
try {
throw new Exception('Test Error');
} catch (\Exception $e) {
Log::stack(['datePayments', 'stack', 'email'])->emergency("user error", ['error' => $e, 'userID'=>Auth::id()]);
}
那么如何配置它才能使它工作?
这里有一个包https://github.com/designmynight/laravel-log-mailer,它为Laravel的LogManager添加了一个邮件驱动程序,它应该完全符合您的要求。