var TPM = (function (name) {return name;}(TPM || {}));

TPM.Log = {

    method : "log",
    level  : "all",
    quietDismiss: true, // may want to just drop, or alert instead,

    _ALL     : "all",
    _NONE    : "none",
    _INFO    : "info",
    _WARNING : "warn",
    _ERROR   : "error",
    _DEBUG   : "debug",    
    
    _hasConsole: function(_method)
    {
        var _method = _method || "log";
        return typeof(console) == 'object' && typeof(console[_method]) != "undefined";
    },
    _consoleMethod: function()
    {
    	if ( this.level == this._NONE ) { //|| TPM.Core.isLoggerOff()
    	    return false;
    	}
    	   
        if ( this.level != this._ALL )
        	if ( this.method != "error"  && ( this.level == this._ERROR ) )
                return false;
        	if ( this.method != "warn"   && ( this.level == this._ERROR || this.level == this._WARNING ) )
                return false;
        	if ( this.method != "info"   && ( this.level == this._ERROR || this.level == this._WARNING || this.level == this._INFO ) )
         	    return false;
            if ( this.method != "log"    && ( this.level == this._ERROR || this.level == this._WARNING || this.level == this._INFO || this.level == this._DEBUG ) )
                return false;

        if (this._hasConsole(this.method)) {
            try {
                console[this.method].apply(this, arguments);
            } catch(e) {
                // safari console may not accept scope like so
                for (var i = 0, l = arguments.length; i < l; i++)
                    console[this.method](arguments[i]);
            }
        } else if(!this.quietDismiss && arguments.length) {
            var result = "";
            for (var i = 0, l = arguments.length; i < l; i++)
                result += arguments[i] + " ("+typeof arguments[i]+") ";
        }
    },

    setLevel: function ( level ) {
    	this.level = level; 
    },
    log: function() {
        this.method = "log";
        this._consoleMethod.apply(this, arguments);
    },
    info: function() {
        this.method = "info";
        this._consoleMethod.apply(this, arguments);
    },
    warn: function() {
        this.method = "warn";
        this._consoleMethod.apply(this, arguments);
    },
    error: function() {
        this.method = "error";
        this._consoleMethod.apply(this, arguments);
    },
    debug: function() {
        this.method = "log";
        this._consoleMethod.apply(this, arguments);
    },
    clear: function() {
        this.method = "clear";
        this._consoleMethod.apply(this);
    },
    count: function() {
        this.method = "count";
        this._consoleMethod.apply(this, arguments);
    },
    trace: function() {
        this.method = "trace";
        this._consoleMethod.apply(this, arguments);
    },
    assert: function() {
        this.method = "assert";
        this._consoleMethod.apply(this, arguments);
    }
};
