Saw something on ajaxian and also a small part of the windowLogger.js inspired this. Right now I have just basics, but you could grab more data about the browser and OS and pass that on to the error handler function.

you need to save this out as a PHP file and include the php file like you would a _javascript_. It works that way.

example <script type="text/_javascript_" src="" ></script>

Here is the code
----- start code -----
<?php
    /*
        to make this work you need to add
        a _javascript_ <script> file to your
        webpage that you want to capture
        javascipt errors.
       
        example:
        <script type="text/_javascript_" SRC="">
    */
    define('_AEL_SCRIPT_URL', 'scripts/ael.php'); // whatever & whereever your ajax error script is called
    define('_AEL_SUPPRESS_DEFAULT_HANDLER', false); // Some browsers don't care about this... and on my opinion, it should always be false. YMMV.
    define('_AEL_M', 'ael_m'); // the error message
    define('_AEL_C', 'ael_c'); // the url of the error
    define('_AEL_T', 'ael_t'); // the line number of the error
    define('_AEL_EXC', 'ael_exc'); // the line number of the error
    define('_AEL_LOG_FILE', '/tmp/QooxdooLog'); // the log file to write to
   
    // error handling function ... to database, flat file, server log, wherever... I just chose to post to custom server log
    function userErrorHandler($t,$m,$c,$exc="")
    {
       // timestamp for the error entry
       $dt = date("Y-m-d H:i:s (T)");
   
   
        switch($t){
       
            case "DEBUG":
                $err = "+++++ DEBUG [ $dt ] +++++\n";
                break;
            case "INFO":
                $err = "----- INFO [ $dt ] -----\n\n";
                break;
            case "WARN":
                $err = "***** WARN [ $dt ] *****\n\n";
                break;
            case "ERROR":
                $err = "##### ERROR [ $dt ] #####\n\n";
                break;
       
        }
       // formulate message however you like
       $err .= "\t $m   $c\n";
       if(!$exc){
               $err .= "\n";
        }else{
            $err .= "\t".$exc."\n\n";
        }

     
       // write the error
       error_log($err, 3, _AEL_LOG_FILE);

    }
   
    if (
        isset($_GET[_AEL_T])
        ||
        isset($_GET[_AEL_M])
        ||
        isset($_GET[_AEL_C])
        ||
        isset($_GET[_AEL_EXC])

    ) {
        $m = isset($_GET[_AEL_M]) ? $_GET[_AEL_M] : 'NO M';
        $c = isset($_GET[_AEL_C]) ? $_GET[_AEL_C] : 'NO C';
        $t = isset($_GET[_AEL_T]) ? $_GET[_AEL_T] : 'NO TC';
        $exc = isset($_GET[_AEL_EXC])? $_GET[_AEL_EXC] : '';
       
        // Here, we can do the logging...
        userErrorHandler($t,$m,$c,$exc);
    } else {
?>




qooxdooLogger = function (type, msg, code, exc) {
    var ajax;
    if (window.XMLHttpRequest) {
        try {
            ajax = new window.XMLHttpRequest(); // XMLHttpRequest (Mozilla, Opera, Safari, etc.)
        } catch (e) {
            ajax = false;
        }
    } else {
        var msXML = new Array( // XMLHttpRequest (IE with ActiveX)
            "Msxml2.XMLHTTP.5.0",
            "Msxml2.XMLHTTP.4.0",
            "Msxml2.XMLHTTP.3.0 ",
            "Msxml2.XMLHTTP",
            "Microsoft.XMLHTTP"
        );
        for (var i = 0; i < msXML.length; i++) { // We want to get the best we can
            try {
                ajax = new ActiveXObject(msXML[i]);
                window.status=i;
                break;
            } catch (e) {
                ajax = false;
            }
        }
    }
   
   
    if (ajax) {
        var data = "">        data += ((data != "") ? "&" : "") + encodeURIComponent('<?php echo(_AEL_T); ?>') + "=" + encodeURIComponent(type);
        data += ((data != "") ? "&" : "") + encodeURIComponent('<?php echo(_AEL_M); ?>') + "=" + encodeURIComponent(msg);
        data += ((data != "") ? "&" : "") + encodeURIComponent('<?php echo(_AEL_C); ?>') + "=" + encodeURIComponent(code);
        data += ((data != "") ? "&" : "") + encodeURIComponent('<?php echo(_AEL_EXC); ?>') + "=" + encodeURIComponent(exc);
        data = '' + data;
        ajax.open('GET', data, true);
        ajax.send(null);
    }
    return <?php (_AEL_SUPPRESS_DEFAULT_HANDLER ? 'true' : 'false') ?>;
}

QxObject.prototype.debug = function(m, c) {
    qooxdooLogger("DEBUG", this.classname+QxObject.DEBUG_MSG_BEFORE+this._hashCode+QxObject.DEBUG_MSG_AFTER+'\n\t'+m, c);
};

QxObject.prototype.info = function(m, c) {
    qooxdooLogger("INFO", m, c);
};

QxObject.prototype.warn = function(m, c) {
    qooxdooLogger("WARN", m, c);
};

QxObject.prototype.error = function(m, exc) {
    qooxdooLogger("ERROR", this.classname + ": " + m, null, exc);
};
<?php
    }
?>

----- end code -----

--
Best regards,
Chris Esler
www.dibolmi.com

Reply via email to