通过IP地址限制Laravel错误日志 [英] Restricting Laravel Error Log by IP Address
问题描述
在Laravel的 app/config.php
中将 debug
设置为 true
时,有任何方法可以限制生成的 Whoops
错误页面,其中包含堆栈跟踪到某些IP地址,并且不在该列表中的IP显示特定视图吗?
When debug
is set to true
in Laravel's app/config.php
is there any way to restrict the resultant Whoops
error page with stack trace to certain IP addresses, and IPs not on that list being shown a specific view?
谢谢.
推荐答案
不是内建的.
但是您可以通过捕获所有异常,并仅在比较用户的IP地址后重新抛出,才能很容易地实现此目的.
But you could probably implement this quite easily by capturing all exceptions and only re-throwing once you've compared the IP address of the user.
因此,在 app/start/global.php
中,您需要配置应用程序错误处理程序".目前,它捕获了所有异常,并简单地使用 Log :: error
记录它们.因此,您可以在其中将用户的IP地址与一组有效的IP地址进行比较:
So in app/start/global.php
you'd need to configure the "Application Error Handler". At the moment it captures all exceptions and simply logs them with Log::error
. So in there you could compare the users IP address with an array of valid IP addresses:
App::error(function(Exception $exception, $code)
{
Log::error($exception);
$validIpAddresses = ['123.456.789.0', '321.654.987.0'];
if (in_array(Request::getClientIp(), $validIpAddresses))
{
throw $exception;
}
return View::make('error');
});
这篇关于通过IP地址限制Laravel错误日志的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!