{"size": 3589, "ext": "js", "max_stars_repo_path": "js/rhoconnect.common.js", "max_stars_repo_name": "edaros/Phonegap-", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "js/rhoconnect.common.js", "max_issues_repo_name": "edaros/Phonegap-", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "js/rhoconnect.common.js", "max_forks_repo_name": "edaros/Phonegap-", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 27.8217054264, "max_line_length": 84, "alphanum_fraction": 0.4530509891}
(function($) {

    function publicInterface() {
        return {
            Logger: Logger,
            ERRORS: RhoConnect.ERRORS,
            deferredMapOn: deferredMapOn,
            passRejectTo: passRejectTo
        };
    }

    var rho = RhoConnect.rho;

    function Logger(name) {

        var levels = {
            trace: 0,
            info: 1,
            warning: 2,
            error: 3,
            fatal: 4
        };
        var levelTag = ['Trace', 'Info', 'Warning', 'Error', 'Fatal'];

        var level = parseLogLevel(rho.config.logLevel);

        this.trace = function(message) {
            var l = levels.trace;
            if (level > l) return;
            withConsole(function(c){
                c.info(buildMsg(l, message));
            });
        };

        this.info = function(message) {
            var l = levels.info;
            if (level > l) return;
            withConsole(function(c){
                c.info(buildMsg(l, message));
            });
        };

        this.warning = function(message, exception) {
            var l = levels.warning;
            if (level > l) return;
            withConsole(function(c){
                c.warn(buildMsg(l, message));
                if (exception) {
                    c.warn('EXCEPTION: ' +exception);
                }
            });
        };

        this.error = function(message, exception) {
            var l = levels.error;
            if (level > l) return;
            withConsole(function(c){
                c.error(buildMsg(l, message));
                if (exception) {
                    c.error('EXCEPTION: ' +exception);
                }
            });
        };

        this.fatal = function(message, exception) {
            var l = levels.fatal;
            if (level > l) return;
            withConsole(function(c){
                c.error(buildMsg(l, message));
                if (exception) {
                    c.error('EXCEPTION: ' +exception);
                }
            });
        };

        function parseLogLevel(name) {
            var isValid = ("string" == typeof name && name.toLowerCase() in levels);
            return isValid ? levels[name.toLowerCase()] : levels.warning;
        }

        function withConsole(callback) {
          if (window.console) {
            callback(window.console)
          }
        }

        function buildMsg(severity, text) {
            var date = Date().replace(/\S+\s(.*?)\sGMT\+.*$/, '$1');
            return date +' [' +levelTag[severity] +']' +' (' +name +') ' +text;
        }
    }

    function passRejectTo(dfr, doReport) {
        return function() {
            if (doReport) {
                //TODO: some log output
            }
            dfr.reject(arguments);
        };
    }

    function deferredMapOn(obj) {
        var dfrMap = {}; // to resolve/reject each exact item
        var dfrs = []; // to watch on all of them

        $.each(obj, function(key, value){
            var dfr = new $.Deferred();
            dfrMap[key] = dfr;
            dfrs.push(dfr.promise());
        });

        return {
            resolve: function(key, args) {
                if (dfrMap[key]) dfrMap[key].resolve.apply(dfrMap[key], args);
            },
            reject: function(key, args) {
                if (dfrMap[key]) dfrMap[key].reject.apply(dfrMap[key], args);
            },
            when: function() {
                return $.when.apply(this, dfrs);
            }
        };
    }

    $.extend(rho, publicInterface());
    $.extend(RhoConnect, {Logger: Logger});

})(jQuery);
