Ejemplo n.º 1
0
 /**
  *  エラーハンドラ
  *
  *  エラー発生時の追加処理を行いたい場合はこのメソッドをオーバーライドする
  *  (アラートメール送信等−デフォルトではログ出力時にアラートメール
  *  が送信されるが、エラー発生時に別にアラートメールをここで送信
  *  させることも可能)
  *
  *  @access public
  *  @param  object  Ethna_Error     エラーオブジェクト
  */
 public function handleError($error)
 {
     // ログ出力
     list($log_level, $dummy) = $this->logger->errorLevelToLogLevel($error->getLevel());
     $message = $error->getMessage();
     $this->logger->log($log_level, sprintf("%s [ERROR CODE(%d)]", $message, $error->getCode()));
 }
/**
 *	エラーコールバック関数
 *
 *	@param	int		$errno		エラーレベル
 *	@param	string	$errstr		エラーメッセージ
 *	@param	string	$errfile	エラー発生箇所のファイル名
 *	@param	string	$errline	エラー発生箇所の行番号
 */
function ethna_error_handler($errno, $errstr, $errfile, $errline)
{
    if ($errno == E_STRICT) {
        // E_STRICTは表示しない
        return E_STRICT;
    }
    list($level, $name) = Ethna_Logger::errorLevelToLogLevel($errno);
    switch ($errno) {
        case E_ERROR:
        case E_CORE_ERROR:
        case E_COMPILE_ERROR:
        case E_USER_ERROR:
            $php_errno = 'Fatal error';
            break;
        case E_WARNING:
        case E_CORE_WARNING:
        case E_COMPILE_WARNING:
        case E_USER_WARNING:
            $php_errno = 'Warning';
            break;
        case E_PARSE:
            $php_errno = 'Parse error';
            break;
        case E_NOTICE:
        case E_USER_NOTICE:
            $php_errno = 'Notice';
            break;
        default:
            $php_errno = 'Unknown error';
            break;
    }
    $php_errstr = sprintf('PHP %s: %s in %s on line %d', $php_errno, $errstr, $errfile, $errline);
    if (ini_get('log_errors') && error_reporting() & $errno) {
        $locale = setlocale(LC_TIME, 0);
        setlocale(LC_TIME, 'C');
        error_log($php_errstr, 0);
        setlocale(LC_TIME, $locale);
    }
    $c =& Ethna_Controller::getInstance();
    $logger =& $c->getLogger();
    $logger->log($level, sprintf("[PHP] %s: %s in %s on line %d", $name, $errstr, $errfile, $errline));
    $facility = $logger->getLogFacility();
    if ($facility != LOG_ECHO && ini_get('display_errors') && error_reporting() & $errno) {
        if ($c->getCLI()) {
            $format = "%s: %s in %s on line %d\n";
        } else {
            $format = "<b>%s</b>: %s in <b>%s</b> on line <b>%d</b><br />\n";
        }
        printf($format, $php_errno, $errstr, $errfile, $errline);
    }
}
Ejemplo n.º 3
0
/**
 *  エラーコールバック関数
 *
 *  @param  int     $errno      エラーレベル
 *  @param  string  $errstr     エラーメッセージ
 *  @param  string  $errfile    エラー発生箇所のファイル名
 *  @param  string  $errline    エラー発生箇所の行番号
 */
function ethna_error_handler($errno, $errstr, $errfile, $errline)
{
    if ($errno === E_STRICT || $errno === E_DEPRECATED || ($errno & error_reporting()) === 0) {
        return;
    }
    list($level, $name) = Ethna_Logger::errorLevelToLogLevel($errno);
    switch ($errno) {
        case E_ERROR:
        case E_CORE_ERROR:
        case E_COMPILE_ERROR:
        case E_USER_ERROR:
            $php_errno = 'Fatal error';
            break;
        case E_WARNING:
        case E_CORE_WARNING:
        case E_COMPILE_WARNING:
        case E_USER_WARNING:
            $php_errno = 'Warning';
            break;
        case E_PARSE:
            $php_errno = 'Parse error';
            break;
        case E_NOTICE:
        case E_USER_NOTICE:
        case E_STRICT:
        case E_DEPRECATED:
            $php_errno = 'Notice';
            break;
        default:
            $php_errno = 'Unknown error';
            break;
    }
    $php_errstr = sprintf('PHP %s: %s in %s on line %d', $php_errno, $errstr, $errfile, $errline);
    // error_log()
    if (ini_get('log_errors')) {
        $locale = setlocale(LC_TIME, 0);
        setlocale(LC_TIME, 'C');
        error_log($php_errstr, 0);
        setlocale(LC_TIME, $locale);
    }
    // $logger->log()
    $c =& Ethna_Controller::getInstance();
    if ($c !== null) {
        $logger =& $c->getLogger();
        $logger->log($level, sprintf("[PHP] %s: %s in %s on line %d", $name, $errstr, $errfile, $errline));
    }
    // printf()
    if (ini_get('display_errors')) {
        $is_debug = true;
        $has_echo = false;
        if ($c !== null) {
            $config =& $c->getConfig();
            $is_debug = $config->get('debug');
            $facility = $logger->getLogFacility();
            $has_echo = is_array($facility) ? in_array('echo', $facility) : $facility === 'echo';
        }
        if ($is_debug == true && $has_echo === false) {
            if ($c !== null && $c->getGateway() === GATEWAY_WWW) {
                $format = "<b>%s</b>: %s in <b>%s</b> on line <b>%d</b><br />\n";
            } else {
                $format = "%s: %s in %s on line %d\n";
            }
            printf($format, $php_errno, $errstr, $errfile, $errline);
        }
    }
}
Ejemplo n.º 4
0
/**
 *  エラーコールバック関数
 *
 *  @param  int     $errno      エラーレベル
 *  @param  string  $errstr     エラーメッセージ
 *  @param  string  $errfile    エラー発生箇所のファイル名
 *  @param  string  $errline    エラー発生箇所の行番号
 */
function ethna_error_handler($errno, $errstr, $errfile, $errline)
{
    if (($errno & error_reporting()) === 0) {
        return;
    }
    list($level, $name) = Ethna_Logger::errorLevelToLogLevel($errno);
    switch ($errno) {
        case E_ERROR:
        case E_CORE_ERROR:
        case E_COMPILE_ERROR:
        case E_USER_ERROR:
            $php_errno = 'Fatal error';
            break;
        case E_WARNING:
        case E_CORE_WARNING:
        case E_COMPILE_WARNING:
        case E_USER_WARNING:
            $php_errno = 'Warning';
            break;
        case E_PARSE:
            $php_errno = 'Parse error';
            break;
        case E_NOTICE:
        case E_USER_NOTICE:
        case E_STRICT:
            $php_errno = 'Notice';
            break;
        case E_USER_DEPRECATED:
        case E_DEPRECATED:
            $php_errno = 'Deprecated';
            break;
        case E_RECOVERABLE_ERROR:
            $php_errno = 'Recoverable error';
            break;
        default:
            $php_errno = 'Unknown error';
            break;
    }
    //ここで$level, $nameを使わないのはなぜ?
    $php_errstr = sprintf('PHP %s:%s, %s: %s in %s on line %d', $level, $name, $php_errno, $errstr, $errfile, $errline);
    //echo $php_errstr . "<br />";
    // error_log()
    if (ini_get('log_errors')) {
        $locale = setlocale(LC_TIME, 0);
        setlocale(LC_TIME, 'C');
        error_log($php_errstr, 0);
        setlocale(LC_TIME, $locale);
    }
    // $logger->log()
    $container = Ethna_Container::getInstance();
    if ($container !== null) {
        $logger = $container->getLogger();
        $logger->log($level, sprintf("[PHP] %s: %s in %s on line %d", $name, $errstr, $errfile, $errline));
    }
    // ignore these errors because so many errors occurs in external libraries (like PEAR)
    if ($errno === E_STRICT) {
        return false;
    }
    if ($errno === E_RECOVERABLE_ERROR) {
        return true;
    }
    // printf()
    if (ini_get('display_errors')) {
        $is_debug = true;
        $has_echo = false;
        if ($container !== null) {
            $config = $container->getConfig();
            $is_debug = $config->get('debug');
            $logger = $container->getLogger();
            $facility = $logger->getLogFacility();
            $has_echo = is_array($facility) ? in_array('echo', $facility) : $facility === 'echo';
        }
        if ($is_debug == true && $has_echo === false && $errno !== E_DEPRECATED) {
            return false;
        }
    }
}