當前位置: 首頁>>代碼示例>>PHP>>正文


PHP GO::logError方法代碼示例

本文整理匯總了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;
 }
開發者ID:ajaboa,項目名稱:crmpuan,代碼行數:75,代碼來源:GO.php


注:本文中的GO::logError方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。