var StringBuffer = function() {
    this.init();
};

StringBuffer.prototype = {
    buff: [],
    init: function() {
        this.buff = [];
    },
	
    append: function(str) {
        this.buff[this.buff.length] = str;
    },
	
    toString: function() {
        return this.buff.join('');
    }
};

var Logger = function() {
	
    var _logLevel = 0;
	
    return {

        LOG_INFO:	1,
        LOG_DEBUG:	2,
        LOG_ERROR:	4,
	
        isLogLevelEnabled: function(logLevel) {
            return (logLevel & _logLevel) == logLevel;
        },
        addLogLevel: function(logLevel) {
            _logLevel = _logLevel | logLevel;
        },
        setLogLevel: function(logLevel) {
            _logLevel = logLevel;
        },
        debug: function(msg, condition) {
            if(this.isLogLevelEnabled(this.LOG_DEBUG)) {
                this.log('DBG: ' + msg, condition);
            }
        },
        info: function(msg, condition) {
            if(this.isLogLevelEnabled(this.LOG_INFO)) {
                this.log('INFO: ' + msg, condition);
            }
        },
        error: function(msg, condition) {
            if(this.isLogLevelEnabled(this.LOG_ERROR)) {
                this.log('ERR: ' + msg, condition);
            }
        },
        log: function(msg, condition) {
			
            var doLog = condition ? condition() : true;
			
            if(doLog) {
                if(typeof console != 'undefined') {
                    console.log(msg);
                }
                else {
                    alert(msg);
                }
            }
        }
		
    };
	
}();
