Laravel 5 错误报告抑制

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/28561509/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 10:57:41  来源:igfitidea点击:

Laravel 5 Error Reporting Suppression

phplaravellaravel-5error-handling

提问by Xystussis

In Laravel 4, it was easy enough to suppress E_NOTICE messages; I can't seem to be able to do this because if I add

在 Laravel 4 中,抑制 E_NOTICE 消息很容易;我似乎无法做到这一点,因为如果我添加

error_reporting(E_ALL ^ E_NOTICE) 

anywhere it simply gets overridden.

在任何地方它都会被覆盖。

This seems to happen around here: (index.php)

这似乎发生在这里:(index.php)

$response = $kernel->handle(
    $request = Illuminate\Http\Request::capture()

);

I have added custom code to handle more "pretty" views of exceptions/errors within Exceptions/Handler.php but I'm struggling to switch off notices (I don't want any of these firing off with notices at all)

我添加了自定义代码来处理 Exceptions/Handler.php 中的异常/错误的更多“漂亮”视图,但我正在努力关闭通知(我根本不希望这些中的任何一个被通知触发)

  • Yes, the issue should be fixed, I'm aware of this, however this is a case where I'd prefer the notices NOT bombing the app on live (I have a custom logging solution for this), and on dev I'd like the notice to show.
  • 是的,问题应该得到解决,我知道这一点,但是在这种情况下,我更喜欢通知不要在现场轰炸应用程序(我有一个自定义的日志记录解决方案),而在开发中我会喜欢的通知显示。

采纳答案by Moppo

In Laravel 5, we can set error_reporting(E_ALL ^ E_NOTICE)inside the AppServiceProviders::bootmethod:

在 Laravel 5 中,我们可以error_reporting(E_ALL ^ E_NOTICE)AppServiceProviders::boot方法内部设置:

public function boot()
{
    //set whatever level you want
    error_reporting(E_ALL ^ E_NOTICE);
} 

回答by Giovanni Casinelli

Are you sure APP_DEBUGin your .envfile is set to false in production? That might override your error_reporting()call.

你确定APP_DEBUG你的.env文件在生产中设置为 false 吗?这可能会覆盖您的error_reporting()呼叫。