{"size": 2825, "ext": "js", "max_stars_repo_path": "wdi5/lib/Logger.js", "max_stars_repo_name": "mikezaschka/wdi5", "max_stars_repo_stars_event_min_datetime": "2020-07-09T14:54:54.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-16T14:54:40.000Z", "max_issues_repo_path": "wdi5/lib/Logger.js", "max_issues_repo_name": "mikezaschka/wdi5", "max_issues_repo_issues_event_min_datetime": "2020-05-05T19:17:03.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-31T15:02:12.000Z", "max_forks_repo_path": "wdi5/lib/Logger.js", "max_forks_repo_name": "mikezaschka/wdi5", "max_forks_repo_forks_event_min_datetime": "2020-11-06T16:49:18.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-24T05:44:08.000Z"}
{"max_stars_count": 41, "max_issues_count": 129, "max_forks_count": 13, "avg_line_length": 25.0, "max_line_length": 73, "alphanum_fraction": 0.4846017699}
// @ts-check
let _logLevel = 'error'; // default
const _prefix = '[node WDI5]';
let _logStorage = [];

/**
 * private
 * writes log entries in local storage object
 * @param {String} type
 * @param {String} _prefix
 * @param {String} logMessage
 * @param {...any} a
 */
var _writeLogStorage = (type, _prefix, logMessage, ...a) => {
    _logStorage.push(type.concat(_prefix, logMessage, ...a));
};

/**
 * module to encapsulate console logging functions error, log, info, warn
 */
module.exports = {
    /**
     * @return currently set logLevel
     */
    getLogLevel: () => {
        return _logLevel;
    },

    /**
     * logs the log storage to console and retuns it
     * @returns {Array} log Messages
     */
    printLogStorage: () => {
        _logStorage.forEach((m) => {
            console.log(m);
        });
        return _logStorage;
    },

    /**
     * @param logLevel {String} error | verbose | silent
     * @retunr currently set loglevel
     */
    setLoglevel: (logLevel) => {
        switch (logLevel) {
            case 'error':
            case '': {
                _logLevel = 'error';
                break;
            }
            case 'verbose': {
                _logLevel = 'verbose';
                break;
            }
            case 'silent': {
                _logLevel = 'silent';
                break;
            }
            default: {
                console.error('no valid log level was set -> no change');
            }
        }
        return _logLevel;
    },

    /**
     * @param {String} Message
     */
    error: (logMessage, ...a) => {
        _writeLogStorage('-ERROR- ', _prefix, logMessage, ...a);
        if (_logLevel !== 'silent') {
            // all other log level
            console.error(_prefix, logMessage, ...a);
            // also throw an error
            throw new Error(_prefix.concat(logMessage, ...a));
        }
        if (_logLevel === 'silent') {
            // anyways throw an error
            throw new Error(_prefix.concat(logMessage, ...a));
        }
    },

    /**
     * @param {String} Message
     */
    log: (logMessage, ...a) => {
        _writeLogStorage('-LOG- ', _prefix, logMessage, ...a);
        if (_logLevel === 'verbose') {
            console.log(_prefix, logMessage, ...a);
        }
    },

    /**
     * @param {String} Message
     */
    info: (logMessage, ...a) => {
        _writeLogStorage('-INFO- ', _prefix, logMessage, ...a);
        if (_logLevel === 'verbose') {
            console.info(_prefix, logMessage, ...a);
        }
    },

    /**
     * @param {String} Message
     */
    warn: (logMessage, ...a) => {
        _writeLogStorage('-VERBOSE- ', _prefix, logMessage, ...a);
        if (_logLevel === 'verbose') {
            console.warn(_prefix, logMessage, ...a);
        }
    }
};
