我试图找出如何在Laravel 5中向我的电子邮件发送错误.我没有太多运气找到任何好的资源.
以前有很好的软件包:https: //github.com/TheMonkeys/laravel-error-emailer 这是在Laravel 4中为你做的.
他们还没有发布Laravel5更新,因为他们改变了错误处理的方式......我也不熟悉.
我有一些我需要监控的Laravel 5应用程序,但除了检查存储上的错误日志之外,我还需要一种更有效的方法.
任何帮助将不胜感激.我知道还有其他人也在寻找这些信息.
Sub*_*ash 27
你可以通过捕获所有错误来做到这一点App\Exceptions\Handler::report().所以在你App/Exceptions/Handler.php添加一个report函数,如果它还没有.
/**
* 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);
}
Run Code Online (Sandbox Code Playgroud)
如果您需要更多信息,请参阅laravel文档表单邮件和错误.
编辑:我找到了为Laravel构建的第三方日志系统
www.understand.io
我玩弄了这个并浏览了Laravel核心文件,并提出了类似于您在错误页面上看到的内容.
您只需创建一个视图文件,即回显电子邮件的$ content
public function report(\Exception $e)
{
if ($e instanceof \Exception) {
$debugSetting = Config::get('app.debug');
Config::set('app.debug', true);
if (ExceptionHandler::isHttpException($e)) {
$content = ExceptionHandler::toIlluminateResponse(ExceptionHandler::renderHttpException($e), $e);
} else {
$content = ExceptionHandler::toIlluminateResponse(ExceptionHandler::convertExceptionToResponse($e), $e);
}
Config::set('app.debug', $debugSetting);
$data['content'] = (!isset($content->original)) ? $e->getMessage() : $content->original;
Mail::queue('errors.emails.error', $data, function ($m) {
$m->to('email@email.com', 'Server Message')->subject('Error');
});
}
return parent::report($e);
}
Run Code Online (Sandbox Code Playgroud)
其他答案似乎很正确。我们不久前已经这样做了,并发现了一个大问题:如果邮件命令失败,可能会导致无限循环,抛出错误并尝试发送相应的电子邮件,这将再次导致失败......这将很快填满日志并杀死您的服务器。
请记住这一点,在这种情况下不要发送电子邮件。
旁注:我决定将其放在答案中,因为它与所有答案相关,不应隐藏在一个评论中。
| 归档时间: |
|
| 查看次数: |
15015 次 |
| 最近记录: |