Laravel 5 Send Errors to Email

前端 未结 9 651
野的像风
野的像风 2021-02-03 10:45

I am trying to figure out how I can send errors to my email in Laravel 5. I haven\'t had much luck finding any good resources.

There used to be good packages like: http

9条回答
  •  遥遥无期
    2021-02-03 11:02

    /config/logging.php

    // ...
            'monitoring-mail' => [
                'driver' => 'custom',
                'via' => App\Logging\Mail::class,
                'level' => env('LOG_MONITORING_MAIL_LEVEL', 'error'),
                'to' => env('LOG_MONITORING_TO'),
                'from' => env('LOG_MONITORING_FROM'),
            ],
    // ...
    

    /app/Logging/Mail.php

    /app/Helpers/Log/MailHandler.php

    to = $to;
            $this->config = (array) $config;
        }
    
        protected function write(array $record): void
        {
            $body = $record['formatted'] ?? $record['message'] ?? '';
            Mail::raw($body, function (Message $message) use ($record) {
                $subject = ($record['level_name'] ?? 'ERROR') . ': ' . ($record['message'] ?? '');
                $message->to($this->to);
                $message->subject($subject);
                if (!empty($this->config['from'])) {
                    $message->from($this->config['from']);
                }
            });
        }
    }
    
    

提交回复
热议问题