本文整理汇总了PHP中GO::logError方法的典型用法代码示例。如果您正苦于以下问题:PHP GO::logError方法的具体用法?PHP GO::logError怎么用?PHP GO::logError使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类GO
的用法示例。
在下文中一共展示了GO::logError方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: errorHandler
/**
* Custom error handler that logs to our own error log
*
* @param int $errno
* @param string $errstr
* @param string $errfile
* @param int $errline
* @return boolean
*/
public static function errorHandler($errno, $errstr, $errfile, $errline)
{
//prevent that the shutdown function will log this error again.
if (self::$_lastReportedError == $errno . $errfile . $errline) {
return;
}
self::$_lastReportedError = $errno . $errfile . $errline;
//log only errors that are in error_reporting
$error_reporting = ini_get('error_reporting');
if (!($error_reporting & $errno)) {
return;
}
$type = "Unknown error";
switch ($errno) {
case E_ERROR:
case E_USER_ERROR:
$type = 'Fatal error';
break;
case E_WARNING:
case E_USER_WARNING:
$type = 'Warning';
break;
case E_NOTICE:
case E_USER_NOTICE:
$type = 'Notice';
break;
}
$errorMsg = "[" . @date("Ymd H:i:s") . "] PHP {$type}: {$errstr} in {$errfile} on line {$errline}";
$user = isset(\GO::session()->values['username']) ? \GO::session()->values['username'] : 'notloggedin';
$agent = isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : 'unknown';
$ip = isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : 'unknown';
$errorMsg .= "\nUser: " . $user . " Agent: " . $agent . " IP: " . $ip . "\n";
if (isset($_SERVER['QUERY_STRING'])) {
$errorMsg .= "Query: " . $_SERVER['QUERY_STRING'] . "\n";
}
$backtrace = debug_backtrace();
array_shift($backtrace);
//first item is this function which we don't have to see
$errorMsg .= "Backtrace:\n";
foreach ($backtrace as $o) {
if (!isset($o['class'])) {
$o['class'] = 'global';
}
if (!isset($o['function'])) {
$o['function'] = 'global';
}
if (!isset($o['file'])) {
$o['file'] = 'unknown';
}
if (!isset($o['line'])) {
$o['line'] = 'unknown';
}
$errorMsg .= $o['class'] . '::' . $o['function'] . ' in file ' . $o['file'] . ' on line ' . $o['line'] . "\n";
}
$errorMsg .= "----------------";
\GO::debug($errorMsg);
\GO::logError($errorMsg);
foreach (self::$_errorLogCallbacks as $callback) {
call_user_func($callback, $errorMsg);
}
if (\GO::config()->debug) {
echo nl2br($errorMsg);
}
/* Execute PHP internal error handler too */
return false;
}