mirror of
https://github.com/Lastorder-DC/rhymix.git
synced 2026-04-02 01:52:10 +09:00
Only use error handler and slowlog when debugging is enabled
This commit is contained in:
parent
6b4d69bcc2
commit
51f985c215
3 changed files with 56 additions and 32 deletions
|
|
@ -138,39 +138,11 @@ class DisplayHandler extends Handler
|
|||
public function getDebugInfo(&$output)
|
||||
{
|
||||
// Check if debugging is enabled for this request.
|
||||
if (!config('debug.enabled'))
|
||||
if (!config('debug.enabled') || !Rhymix\Framework\Debug::isEnabledForCurrentUser())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Check if debugging info should be visible to the current user.
|
||||
$display_to = config('debug.display_to');
|
||||
switch ($display_to)
|
||||
{
|
||||
case 'everyone':
|
||||
break;
|
||||
|
||||
case 'ip':
|
||||
$allowed_ip = config('debug.allow');
|
||||
foreach ($allowed_ip as $range)
|
||||
{
|
||||
if (Rhymix\Framework\IpFilter::inRange(RX_CLIENT_IP, $range))
|
||||
{
|
||||
break 2;
|
||||
}
|
||||
}
|
||||
return;
|
||||
|
||||
case 'admin':
|
||||
default:
|
||||
$logged_info = Context::get('logged_info');
|
||||
if ($logged_info && $logged_info->is_admin === 'Y')
|
||||
{
|
||||
break;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// Print debug information.
|
||||
switch ($display_type = config('debug.display_type'))
|
||||
{
|
||||
|
|
|
|||
|
|
@ -308,7 +308,10 @@ class Debug
|
|||
*/
|
||||
public static function registerErrorHandlers($error_types)
|
||||
{
|
||||
set_error_handler('\\Rhymix\\Framework\\Debug::addError', $error_types);
|
||||
if (Config::get('debug.enabled'))
|
||||
{
|
||||
set_error_handler('\\Rhymix\\Framework\\Debug::addError', $error_types);
|
||||
}
|
||||
set_exception_handler('\\Rhymix\\Framework\\Debug::exceptionHandler');
|
||||
register_shutdown_function('\\Rhymix\\Framework\\Debug::shutdownHandler');
|
||||
}
|
||||
|
|
@ -346,6 +349,51 @@ class Debug
|
|||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if debugging is enabled for the current user.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function isEnabledForCurrentUser()
|
||||
{
|
||||
static $cache = null;
|
||||
if ($cache !== null)
|
||||
{
|
||||
return $cache;
|
||||
}
|
||||
if (!Config::get('debug.enabled'))
|
||||
{
|
||||
return $cache = false;
|
||||
}
|
||||
|
||||
$display_to = Config::get('debug.display_to');
|
||||
switch ($display_to)
|
||||
{
|
||||
case 'everyone':
|
||||
return $cache = true;
|
||||
|
||||
case 'ip':
|
||||
$allowed_ip = Config::get('debug.allow');
|
||||
foreach ($allowed_ip as $range)
|
||||
{
|
||||
if (Rhymix\Framework\IpFilter::inRange(RX_CLIENT_IP, $range))
|
||||
{
|
||||
return $cache = true;
|
||||
}
|
||||
}
|
||||
return $cache = false;
|
||||
|
||||
case 'admin':
|
||||
default:
|
||||
$logged_info = \Context::get('logged_info');
|
||||
if ($logged_info && $logged_info->is_admin === 'Y')
|
||||
{
|
||||
return $cache = true;
|
||||
}
|
||||
return $cache = false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all debug information as an object.
|
||||
*
|
||||
|
|
|
|||
|
|
@ -712,12 +712,16 @@ function debugPrint($entry = null)
|
|||
*/
|
||||
function writeSlowlog($type, $elapsed_time, $obj)
|
||||
{
|
||||
static $config = array();
|
||||
static $config = null;
|
||||
if (!$config)
|
||||
{
|
||||
$config = config('debug');
|
||||
}
|
||||
if(!$config['log_slow_queries'] && !$config['log_slow_triggers'] && !$config['log_slow_widgets'])
|
||||
if (!Rhymix\Framework\Debug::isEnabledForCurrentUser())
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (!$config['log_slow_queries'] && !$config['log_slow_triggers'] && !$config['log_slow_widgets'])
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue