var noop = () => {};

var isConsoleAvailable = (action) => {
    var { console } = window;
    return !!console && typeof console[action] === "function";
};

var makeAction = (action, prefix, predicate) => {
    return predicate() ? (...args) => {
        if (isConsoleAvailable(action)) {
            console[action].apply(console, [prefix].concat(args)); // eslint-disable-line
        }
    } : noop;
};

function Logger(prefix = "", predicate = () => true) {
    this.log = makeAction("log", prefix, predicate);
    this.warn = makeAction("warn", prefix, predicate);
    this.error = makeAction("error", prefix, predicate);
}

module.exports = Logger;
