当前位置: 首页>>代码示例>>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;未经允许,请勿转载。