Exemple #1
0
/**
 * HandlePHPErrors
 * This calls the log system to handle the logging of the messages.
 * If error_reporting is disabled this does nothing.
 * This is the function to call for set_error_handler to use to do all of the logging.
 * The GetLogSystem function is one you have to write yourself.
 *
 * <b>Example</b>
 *
 *	require('path/to/log/interspire_log.php');
 *	function GetLogSystem()
 *	{
 *		static $logsystem = null;
 *		if (is_null($logsystem)) {
 *			$logsystem = new Interspire_Log(true, false);
 *
 *			// log which parts of the query string?
 *			// can be an array or a singular item.
 *			$logsystem->SetLogActionStrings(array('todo', 'action', 'save'));
 *
 *			// add whatever extra log types are needed.
 *			// these are on top of the built in types of 'php' and 'sql'.
 *			$logsystem->SetValidLogTypes(array('notifications', 'blogs', 'shipping'));
 *
 *			// set the types of errors/reports we're actually going to save.
 *			$logsystem->SetLogTypes(array('sql','php'));
 *
 *			$db = &GetDatabase();
 *			// need to connect the database to the log system so it can do it's work.
 *			// it's handled by reference inside the SetDb method.
 *			$logsystem->SetDb($db);
 *
 *			$logsystem->SetSeverities('all');
 *		}
 *		return $logsystem;
 *	}
 *
 * 	// then set the error handler.
 *	set_error_handler('HandlePHPErrors');
 *
 *
 * @param Int $errno The error number we are logging. This is one of the defined constants like 'E_USER_ERROR'.
 * @param String $errstr The error message to log.
 * @param String $errfile The filename the error occurred in.
 * @param Int $errline The line number the error occurred on.
 *
 * @return Mixed Returns straight away if error_reporting is disabled. Otherwise it calls the log system to handle the error and then returns true so the error isn't output to the browser.
 */
function HandlePHPErrors($errno, $errstr, $errfile, $errline)
{
    // Error reporting turned off (either globally or by @ before erroring statement)
    if (error_reporting() == 0) {
        return;
    }
    if (!defined('E_STRICT')) {
        define('E_STRICT', 2048);
    }
    if ($errno === E_STRICT) {
        return;
    }
    $logsystem = GetLogSystem();
    $msg = "{$errstr} in {$errfile} at {$errline}<br/>\n";
    $msg .= $logsystem->trace(false, true);
    // This switch uses case fallthrough's intentionally
    switch ($errno) {
        case E_USER_ERROR:
        case E_ERROR:
        case E_PARSE:
        case E_CORE_ERROR:
        case E_COMPILE_ERROR:
            $logsystem->LogSystemError('php', substr($errstr, 0, 250), $msg);
            exit(1);
            break;
        case E_USER_WARNING:
        case E_WARNING:
        case E_CORE_WARNING:
        case E_COMPILE_WARNING:
            $logsystem->LogSystemWarning('php', substr($errstr, 0, 250), $msg);
            break;
        case E_USER_NOTICE:
        case E_NOTICE:
            $logsystem->LogSystemNotice('php', substr($errstr, 0, 250), $msg);
            break;
        case E_STRICT:
            //$logsystem->LogSystemNotice('php', substr($errstr, 0, 250), $msg);
            break;
        default:
            $logsystem->LogSystemNotice('php', substr($errstr, 0, 250), $msg);
            break;
    }
    /* Don't execute PHP internal error handler */
    return true;
}
 /**
  * SetPruneLog
  * Sets the Interspire Logger to only keep the configured amount of log entries.
  * This function is triggered by the IEM_SYSTEM_STARTUP_AFTER event.
  *
  * @uses IEM_SYSTEM_STARTUP_AFTER
  *
  * @return Void Does not return anything.
  */
 public static function SetPruneLog()
 {
     $settings = self::GetSettings();
     $logsystem = GetLogSystem();
     if ($logsystem) {
         $logsystem->SetGeneralLogSize($settings['logsize']);
     }
 }
Exemple #3
0
        // This is the new page structure
    } else {
        require_once IEM_PATH . "/pages/{$newPage}.class.php";
        $tempClassName = "page_{$newPage}";
        $tempAction = 'page_' . preg_replace('/[^\\w]/', '_', IEM::requestGetGET('action', 'index'));
        $tempPageObject = new $tempClassName();
        // Check if "action" exists
        if (!is_callable(array($tempPageObject, $tempAction))) {
            // page_index will alwas exists (albeit only returning a FALSE)
            $tempAction = 'page_index';
        }
        // Call the function specified by "action" parameter
        $tempOutput = $tempPageObject->{$tempAction}();
        // TODO other return value have no effect at the moment.
        // Currently it only prints out a string
        if (is_string($tempOutput)) {
            echo $tempOutput;
        }
        // Call the page class destructor if it wants to cleanup anything
        unset($tempPageObject);
    }
    // After everything has run, see if we need to keep the "logs" in check.
    $logsystem = GetLogSystem();
    if ($logsystem) {
        $logsystem->PruneSystemLog();
        $logsystem->PruneAdminLog();
        unset($logsystem);
    }
    // The controller should end the request.
    exit;
}