如何使用laravel 5.6和monolog通过电子邮件发送错误日志

问题描述 投票:0回答:1

在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()]);
    }

那么如何配置它才能使它工作?

swiftmailer laravel-5.6 monolog
1个回答
2
投票

这里有一个包https://github.com/designmynight/laravel-log-mailer,它为Laravel的LogManager添加了一个邮件驱动程序,它应该完全符合您的要求。

© www.soinside.com 2019 - 2024. All rights reserved.