/*
helper function to debug, calls console.log on every value returnin the parent stream
328481
function log(parent$, prefix) {
  map(parent$, value => console.log(prefix, value));
  return parent$;
}
1354740
function ConsoleLogger() {

    this.error = function () {
        if (loggingLevel(ERROR)) {
            console.error.apply(this, arguments);
        }
    };

    this.warn = function () {
        if (loggingLevel(WARN)) {
            console.warn.apply(this, arguments);
        }
    };

    this.info = function () {
        if (loggingLevel(INFO)) {
            console.info.apply(this, arguments);
        }
    };

    this.log = function () {
        if (loggingLevel(INFO)) {
            console.log.apply(this, arguments);
        }
    };

    this.debug = function () {
        if (loggingLevel(DEBUG)) {
            console.log.apply(this, arguments);
        }
    };

    this.setLevelToInfo = function () {
        setLevel(INFO);
    };

    this.setLevelToDebug = function() {
        setLevel(DEBUG);
    };

    this.setLevelToWarning = function() {
        setLevel(WARN);
    };

    this.setLevelToError = function() {
        setLevel(ERROR);
    };
}
991071
function log(type) {
  var messages = Array.prototype.slice.call(arguments);
  messages.shift();
  // Concatenate default strings and first message argument into
  // one string so we can use `printf`-like replacement
  var first = "JPM [" + type + "] " + (messages.shift() + "");

  if (process.env.NODE_ENV !== "test") {
    console.log.apply(console, [first].concat(messages)); // eslint-disable-line no-console
  }
}
331944
private InputStream debugInputStream(InputStream in) throws IOException {
        if (logger.isLoggable(Level.FINEST)) {
            final byte[] buffer = new byte[1024];
            final ByteArrayOutputStream baos = new ByteArrayOutputStream();
            int len;
            String line;

            logger.finest("[START] Dumping the InputStream that will be passed to JSON.parse()");
            while ((len = in.read(buffer)) > -1) {
                baos.write(buffer, 0, len);
            }
            baos.flush();

            ByteArrayInputStream dumpIn = new ByteArrayInputStream(baos.toByteArray());
            BufferedReader br = new BufferedReader(new InputStreamReader(dumpIn));
            while ((line = br.readLine()) != null) {
                logger.finest(line);
            }
            logger.finest("[END] Dumping the InputStream that will be passed to JSON.parse()");

            return new ByteArrayInputStream(baos.toByteArray());
        } else {
            return in;

        }
    }
784174
function() {
    var con = {};
    con.log = console.log;
    con.warn = console.warn;
    con.info = console.info;
    con.error = console.error;

    var fu = function(type, args) {
      if (!self.uiPrompt.rl || !process.stdout.columns) {
        return con[type].apply(con, args);
      }

      var t = Math.ceil(
        (self.uiPrompt.rl.line.length + 3) / process.stdout.columns
      );
      var text = util.format.apply(console, args);

      self.uiPrompt.rl.output.unmute();
      self.uiPrompt.rl.output.write('\n\x1B[' + t + 'A\x1B[0J');
      self.uiPrompt.rl.output.write(text + '\n');
      self.uiPrompt.rl.output.write(new Array(t).join('\n\x1B[E'));
      self.uiPrompt.rl._refreshLine();
      self.uiPrompt.rl.output.mute();
    };

    console.log = function() {
      fu('log', arguments);
    };
    console.warn = function() {
      fu('warn', arguments);
    };
    console.info = function() {
      fu('info', arguments);
    };
    console.error = function() {
      fu('error', arguments);
    };
  }
863049
function LogDraft(console, methodName) {
  this._stream = console._stdout
  this._styleFn = console[methodName]

  // Valid flag. If set to false, should NOT write anymore
  this.valid = true

  // Save line where content will be saved
  this.saveLine()
}
122398
function(obj,callback,scope,breakerfunc,complete){
         if(!obj || !callback) return false;

         if(typeof obj === 'string') obj = this.values(obj);

         if(('length' in obj && !this.isFunction(obj) && !this.isObject(obj)) || this.isArray(obj) || this.isString(obj)){
            return this._eachArray(obj,callback,scope,breakerfunc,complete);
         }
         if(this.isObject(obj) || this.isFunction(obj)){
            return this._eachObject(obj,callback,scope,breakerfunc,complete);
         }
    }
907426
function genericLog(logger, moduletag, logLevel='info'){
  const isDebug = logLevel==='debug'
  const level = isDebug
    ? 'info'
    : logLevel
  const levelLogger = logger[level]
  const active = isDebug
    ? enabled(moduletag)
    : true

  /**
   * tagged Logger
   * @function taggedLog
   * @param {...string} tags Optional message tags
   */
  function taggedLog(...tags) {
    const tag = normalizeDefaults(tags)
    /**
     * message Logger
     * @function messageLog
     * @template T
     * @param {...T} messages message
     * @returns {T}
     */
    function messageLog(...messages) {
      if (active) {
        const protectedMessage = messageArrayProtect(messages)
        levelLogger(tag, ...protectedMessage)
      }
      return messages[0]
    }
    return messageLog
  }
  /**
   * Array logge Prinst every value on separated line
   * @function mapLog
   * @param {...string} tags Optional message tags
   */
  function mapLog(...tags) {
    /**
     * Array logge Prinst every value on separated line
     * @function printArray
     * @param {Array} message Printed list
     * @returns {Array}
     */
    function printArray(message) {
      if (active) {
        arrayCheck(message)
        const tag = normalizeDefaults(tags)
        //count length + 2. Also handles edge case with objects without 'length' field
        const spaceLn = P(
          length,
          defaultTo(0),
          add(2) )
        const ln = sum( map( spaceLn, tags ) )
        const spaces = new Array(ln)
          .fill(' ')
          .join('')

        const getFormatted = num => chalk.green(`<${num}>`)
        levelLogger( tag, getFormatted(0), head( message ) )
        const printTail = (e, i) => levelLogger(spaces, getFormatted(i+1), e)

        P(
          tail,
          indexedMap(printTail)
        )(message)
      }
      return message
    }
    return printArray
  }
  taggedLog.map = mapLog
  return taggedLog
}
704482
function printBuffer () {
  let { header, prev, next, action, msgs } = displayBuffer
  if (console.group) {
    console.groupCollapsed(...header)
    console.log(...prev)
    console.log(...action)
    console.log(...next)
    console.log(...msgs)
    console.groupEnd()
  } else {
    console.log(...header)
    console.log(...prev)
    console.log(...action)
    console.log(...next)
    console.log(...msgs)
  }
}
418752
function reduce(parent$, fn, startValue) {
  let aggregate = startValue;
  let newStream = stream();
  function reduceValue(value) {
    aggregate = fn(aggregate, parent$.value);
    newStream(aggregate);
  }
  if (parent$.value !== undefined) {
    reduceValue(parent$.value);
  }
  parent$.listeners.push(reduceValue);
  return newStream;
}
654893
function log() {
  var args = NS ? [chalk.bold.gray(NS)] : []
  for(var i=0; i<arguments.length; i++) {
    var arg = arguments[i];
    args.push(chalk.cyan( typeof arg === "object" ? JSON.stringify(arg) : arg ))

    // adds a separator
    if(i < arguments.length-1) args.push(chalk.gray("|"));
  }
  if(testLog)   testLog(args);
  else          console.log.apply(null, args)
}
1105203
function (obj, tag) {
        tag = _.isArray(tag) ? tag.join(',') : tag;
        tag = !_.isEmpty(tag) ? tag.toLowerCase() : 'default';

        obj.trace = function (message, data) {
            _logEvent("trace", message, tag, data);
        };

        obj.debug = function (message, data) {
            _logEvent("debug", message, tag, data);
        };

        obj.info = function (message, data) {
            _logEvent("info", message, tag, data);
        };

        obj.warn = function (message, data) {
            _logEvent("warn", message, tag, data);
        };

        obj.error = function (message, data) {
            _logEvent("error", message, tag, data);
        };

        obj.fatal = function (message, data) {
            _logEvent("fatal", message, tag, data);
        };

        return obj;
    }
322424
function Logger_write() {
            var log = this.logs.shift();

            if (log && (this.config.type === log.type || this.config.type === 'ALL')) {
                if (this.config.console) {
                    if (log.type === 'ERROR') {
                        exec_console(console.error, log, this.config.streamFormat);
                    } else if (log.type === 'INFO') {
                        exec_console(console.info, log, this.config.streamFormat);
                    } else if (log.type === 'WARNING') {
                        exec_console(console.warn, log, this.config.streamFormat);
                    } else {
                        exec_console(console.log, log, this.config.streamFormat);
                    }
                }

                if (this.stream) {
                    if (this.config.streamFormat === 'json') {
                        this.stream.write(JSON.stringify(log));
                        this.stream.write('\n');
                    } else {
                        this.stream.write('TYPE: ' + log.type);
                        this.stream.write('\n');
                        this.stream.write('CREATED: ' + log.created + '\t ');
                        this.stream.write('\n');
                        this.stream.write('MESSAGE: ' + log.message + '\t ' + log.trace);
                        this.stream.write('\n');
                        this.stream.write('DATA: ' + this.clean(log.data));
                        this.stream.write('\n');
                        this.stream.write('\n');
                    }
                }
                // clean log data for hook
                log.data = this.clean(log.data);
                // call log
                this.hooks.forEach(function (callback) {
                    callback(log);
                });
            }
            /**
             * Exec console output
             * @param func
             * @param log
             */
            function exec_console(func, log, format) {
                if (format === 'json') {
                    func(JSON.stringify(log));
                } else {
                    func(
                        ' ' + log.type + '\n',
                        'CREATED: ' + log.created + '\t ' + '\n',
                        'MESSAGE: ' + log.message + '\t ' + log.trace + '\n',
                        !!log.data ? 'DATA:' + log.data + '\n' : '',
                        '\n'
                    );
                }
            };
        }
912671
function() {
    var oThis = this;

    var argsPassed = oThis._filterArgs(arguments);

    var args = [oThis.getPrefix(this.ERR_PRE)];
    args = args.concat(Array.prototype.slice.call(argsPassed));
    args.push(this.CONSOLE_RESET);
    console.log.apply(console, args);
  }
583787
function streamToJsonValue (res, cb) {
  streamToValue(res, (err, data) => {
    if (err) {
      return cb(err)
    }

    if (!data || data.length === 0) {
      return cb()
    }

    // TODO: check if needed, afaik JSON.parse can parse Buffers
    if (Buffer.isBuffer(data)) {
      data = data.toString()
    }

    let res
    try {
      res = JSON.parse(data)
    } catch (err) {
      return cb(err)
    }

    cb(null, res)
  })
}
1242607
function MultiLine()
{

    MultiLine.prototype.parse_and_print = function(msg, colour)
    {
        var out = [];
        for (var i = 0; i < msg.length; i++)
        {
            var msg_item = msg[i];
            if (typeof msg_item == 'object')
                out.push(colour + RESET + util.inspect(msg_item, false, 50, true) + RESET + colour);
            else
                out.push(msg_item);
        }
        this.print(colour + out.join(' ') + colour + " " + RESET);
    };

    MultiLine.prototype.info = function(msg)
    {
        this.parse_and_print(msg, GREEN);
    };

    MultiLine.prototype.mark = function(msg)
    {
        this.parse_and_print(msg, LIGHT_GREEN);
    };

    MultiLine.prototype.error = function(msg)
    {
        this.parse_and_print(msg, RED);
    };

    MultiLine.prototype.warn = function(msg)
    {
        this.parse_and_print(msg, YELLOW);
    };

    MultiLine.prototype.print = function(msg)
    {
        console.log(msg);
    };
}
67809
function Logger(ctx) {
    _console = window ? window.console : {};
    _global = window ? window : {};
    this._timers = {};
    this.args = function(context, level, args) {
        let logHeader = '%c '+level+' %c'+(new Date().toISOString())+' %c'+context;
        const colors = [_bc+_c1, _bc+_c2, _bc+_c3];
        for (let i = 0; i < args.length; i++) {
            if (typeof args[i] == 'string' && args[i].indexOf('timer:') === 0) {
                const t = args[i].split(':');
                if (t.length === 3) {
                    let elapsed;
                    switch (t[2]) {
                        case 'start':
                            this._timers[t[1]] = new Date().getTime();
                            logHeader += ' %cSTART '+t[1];
                            colors.push(_bc+_c_start);
                            break;
                        case 'stop':
                            elapsed = (new Date().getTime() - this._timers[t[1]]);
                            logHeader += ' %cSTOP '+t[1]+' '+elapsed+' ms';
                            if (elapsed > 200) {
                                colors.push(_bc+_c_end_very_slow);
                            } else if (elapsed > 100) {
                                colors.push(_bc+_c_end_slow);
                            } else {
                                colors.push(_bc+_c_end);
                            }
                            break;
                    }
                }
            }
        }
        logHeader += ' \n%c '; colors.push(_bt+'color:inherit;');
        // if (typeof args[0] == 'string') {
        //     logHeader += ' %c' + args[0];
        //     Array.prototype.shift.call(args);
        // }
        for (let c = colors.length-1; c >= 0; c--) {
            Array.prototype.unshift.call(args, colors[c]);
        }
        Array.prototype.unshift.call(args, logHeader);
        Array.prototype.push.call(args, '\n\n');
    };
    this.log = function(level, args) {
        if (typeof _callback === 'function') {
            _callback.call(ctx, level, args);
        }
        // route event
        if (!_global.zuixNoConsoleOutput) {
            this.args(ctx, level, args);
            _console.log.apply(_console, args);
        }
    };
}