shaffe / laravel-mail-log-channel
一个用于支持通过电子邮件在 Laravel 中进行日志记录的包
v2.4.0
2024-03-12 22:53 UTC
Requires
- illuminate/bus: ^5.6|^6.0|^7.0|^8.0|^9.0|^10.0|^11.0
- illuminate/contracts: ^5.6|^6.0|^7.0|^8.0|^9.0|^10.0|^11.0
- illuminate/log: ^5.6|^6.0|^7.0|^8.0|^9.0|^10.0|^11.0
- illuminate/mail: ^5.6|^6.0|^7.0|^8.0|^9.0|^10.0|^11.0
- illuminate/queue: ^5.6|^6.0|^7.0|^8.0|^9.0|^10.0|^11.0
- illuminate/support: ^5.6|^6.0|^7.|^8.00|^9.0|^10.|^11.00
README
一个服务提供者,用于通过 Laravel 内置的邮件提供者添加通过电子邮件进行日志记录的支持。
此包是 Steve Porter 的 laravel-log-mailer 的分支。
目录
安装
您可以使用以下命令通过 composer 安装此包:
composer require shaffe/laravel-mail-log-channel
Laravel 版本兼容性
如果您使用 Laravel,则此包将自动注册自己。
要使用 Lumen,请在 bootstrap/app.php
中添加服务提供者。
$app->register(Shaffe\MailLogChannel\MailLogChannelServiceProvider::class);
配置
为确保所有未处理的异常都被发送邮件
- 在
config/logging.php
中创建一个mail
日志通道 - 将此
mail
通道添加到您的当前日志堆栈中 - 在
.env
文件中添加LOG_MAIL_ADDRESS
以定义收件人
您可以指定多个通道,并单独更改收件人、主题和电子邮件模板。
'channels' => [ 'stack' => [ 'driver' => 'stack', // 2. Add mail to the stack: 'channels' => ['single', 'mail'], ], // ... // 1. Create a mail logging channel: 'mail' => [ 'driver' => 'mail', 'level' => env('LOG_MAIL_LEVEL', 'notice'), // Specify mail recipient 'to' => [ [ 'address' => env('LOG_MAIL_ADDRESS'), 'name' => 'Error', ], ], 'from' => [ // Defaults to config('mail.from.address') 'address' => env('LOG_MAIL_ADDRESS'), // Defaults to config('mail.from.name') 'name' => 'Errors' ], // Optionally overwrite the subject format pattern // 'subject_format' => env('LOG_MAIL_SUBJECT_FORMAT', '[%datetime%] %level_name%: %message%'), // Optionally overwrite the mailable template // Two variables are sent to the view: `string $content` and `array $records` // 'mailable' => NewLogMailable::class ], ],
收件人配置格式
以下 to
配置格式被支持:
-
单个电子邮件地址
'to' => env('LOG_MAIL_ADDRESS', ''),
-
电子邮件地址数组
'to' => explode(',', env('LOG_MAIL_ADDRESS', '')),
-
电子邮件 => 名称的关联数组
'to' => [env('LOG_MAIL_ADDRESS', '') => 'Error'],`
-
电子邮件和名称的数组
'to' => [ [ 'address' => env('LOG_MAIL_ADDRESS', ''), 'name' => 'Error', ], ],