Laravel 5将错误发送到电子邮件

编程入门 行业动态 更新时间:2024-10-21 12:00:25
本文介绍了Laravel 5将错误发送到电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我试图弄清楚如何在Laravel 5中向我的电子邮件发送错误.我没有太多运气找到任何好的资源.

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.

曾经有一些不错的软件包,例如: github/TheMonkeys/laravel-error-emailer 这是在Laravel 4中为您完成的.

There used to be good packages like: github/TheMonkeys/laravel-error-emailer That did this for you in Laravel 4.

由于他们更改错误处理的方式,他们尚未发布Laravel5更新...我也不熟悉.

They have yet to release a Laravel5 update because of the way they changed error handling... which I am also not to familiar with.

我有一些Laravel 5应用程序需要监视,但除了检查存储中的错误日志外,我还需要一种更有效的方法.

I have a few Laravel 5 applications which I need to monitor but I need a more efficient way of doing it besides checking error logs on storage.

任何帮助将不胜感激.我知道还有其他人也在寻求这些信息.

Any help would be greatly appreciated. I know there are others out there seeking this information as well.

推荐答案

您可以通过捕获App\Exceptions\Handler::report()中的所有错误来做到这一点.因此,在App/Exceptions/Handler.php中添加report函数(如果尚不存在的话).

You can do this by catching all the errors in the App\Exceptions\Handler::report(). So in you App/Exceptions/Handler.php add a report function if its not already there.

/** * Report or log an exception. * * This is a great spot to send exceptions to Sentry, Bugsnag, etc. * * @param \Exception $e * @return void */ public function report(\Exception $e) { if ($e instanceof \Exception) { // emails.exception is the template of your email // it will have access to the $error that we are passing below Mail::send('emails.exception', ['error' => $e->getMessage()], function ($m) { $m->to('your email', 'your name')->subject('your email subject'); }); } return parent::report($e); }

如果您需要更多信息,请参阅laravel文档表格邮件程序和错误.

If you need more info, refer to laravel documentation form mailer and errors.

更多推荐

Laravel 5将错误发送到电子邮件

本文发布于:2023-10-13 00:00:08,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1486239.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:发送到   电子邮件   错误   Laravel

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!