var _ = require('lodash'),
    rewriteStack = require('../exec').rewriteStack;

module.exports = function(window) {
  window.console = {
    log: delegate('log'),
    info: delegate('info'),
    error: delegate('error'),
    warn: delegate('warn'),

    time: delegate('time'),
    timeEnd: delegate('timeEnd')
  };
};

function delegate(name) {
  return function() {
    console[name].apply(console, mapArgs(arguments));
  };
}

function mapArgs(args) {
  return _.map(args, function(arg) {
    if (arg && arg.split) {
      arg = rewriteStack(arg);
    }
    return arg;
  });
}

var _ = require('lodash'),
    rewriteStack = require('../exec').rewriteStack;

module.exports = function(window) {
  window.console = {
    log: delegate(window, 'log'),
    info: delegate(window, 'info'),
    error: delegate(window, 'error'),
    warn: delegate(window, 'warn'),

    time: delegate(window, 'time'),
    timeEnd: delegate(window, 'timeEnd')
  };
};

function delegate(window, name) {
  return function() {
    console[name].apply(console, mapArgs(arguments).concat(['id_' + window._id]));
  };
}

function mapArgs(args) {
  return _.map(args, function(arg) {
    if (arg && arg.split) {
      arg = rewriteStack(arg);
    }
    return arg;
  });
}

Add window._id to all console operations