shaffe/laravel-mail-log-channel

一个用于支持通过电子邮件在 Laravel 中进行日志记录的包

v2.4.0 2024-03-12 22:53 UTC

This package is auto-updated.

Last update: 2024-09-13 00:25:20 UTC


README

Latest Stable Version Total Downloads License: MIT

一个服务提供者,用于通过 Laravel 内置的邮件提供者添加通过电子邮件进行日志记录的支持。

此包是 Steve Porter 的 laravel-log-mailer 的分支。

image

目录

安装

您可以使用以下命令通过 composer 安装此包:

composer require shaffe/laravel-mail-log-channel

Laravel 版本兼容性

如果您使用 Laravel,则此包将自动注册自己。

要使用 Lumen,请在 bootstrap/app.php 中添加服务提供者。

$app->register(Shaffe\MailLogChannel\MailLogChannelServiceProvider::class);

配置

为确保所有未处理的异常都被发送邮件

  1. config/logging.php 中创建一个 mail 日志通道
  2. 将此 mail 通道添加到您的当前日志堆栈中
  3. .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',
         ],
     ],