Laravel 5将错误发送到电子邮件 [英] Laravel 5 Send Errors to Email
问题描述
我试图弄清楚如何在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.
曾经有一些不错的软件包,例如: https://github.com/TheMonkeys/laravel-error-emailer 这是在Laravel 4中为您完成的.
There used to be good packages like: https://github.com/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将错误发送到电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!