﻿/*

Author: Jonathan Bourke
Date:   27/02/2009

This script defines an object within the scope of the window. The intent of this object
is to wrap up access to the console. In FF we use Firebug to log items to the console,
in IE we might use JSCompanion. If the browser has no console or the methods used
do not exist then this script will simply ignore the call therefore allowing code
to have log calls that get ignored.

*/
window.Logger = (function(){
    
    var _haveConsole = false;
    var _haveConsoleAssert = false;
    var _haveConsoleDebug = false;
    var _haveConsoleDirXML = false;
    var _haveConsoleError = false;
    var _haveConsoleInfo = false;
    var _haveConsoleLog = false;
    var _haveConsoleTime = false;
    var _haveConsoleTimeEnd = false;
    var _haveConsoleWarn = false;
    
    if ( typeof console !== "undefined" ) {
        _haveConsole = true;
        if ( console.log ) {
            _haveConsoleLog = true;
        }
        if ( console.assert ) {
            _haveConsoleAssert = true;
        }
        if ( console.error ) {
            _haveConsoleError = true;
        }
        if ( console.debug ) {
            _haveConsoleDebug = true;
        }
        if ( console.dirxml ) {
            _haveConsoleDirXML = true;
        }
        if ( console.info ) {
            _haveConsoleInfo = true;
        }
        if ( console.time ) {
            _haveConsoleTime = true;
        }
        if ( console.timeEnd ) {
            _haveConsoleTimeEnd = true;
        }
        if ( console.warn ) {
            _haveConsoleWarn = true;
        }
    }
    
    return {
        
        assert: function() {
            if ( _haveConsoleAssert ) {
                console.assert.apply( console, arguments );
            }
        },
        
        debug: function() {
            if ( _haveConsoleDebug ) {
                console.debug.apply( console, arguments );
            }
        },
        
        dirxml: function() {
            if ( _haveConsoleDirXML ) {
                console.dirxml.apply( console, arguments );
            }
        },
        
        error: function() {
            if ( _haveConsoleError ) {
                console.error.apply( console, arguments );
            }
        },
        
        info: function() {
            if ( _haveConsoleInfo ) {
                console.info.apply( console, arguments );
            }
        },
        
        log: function() {
            if ( _haveConsoleLog ) {
                console.log.apply( console, arguments );
            }
        },
        
        time: function() {
            if ( _haveConsoleTime ) {
                console.time.apply( console, arguments );
            }
        },
        
        timeEnd: function() {
            if ( _haveConsoleTimeEnd ) {
                console.timeEnd.apply( console, arguments );
            }
        },
        
        warn: function() {
            if ( _haveConsoleWarn ) {
                console.warn.apply( console, arguments );
            }
        }
        
    };
})();
