var path = require('path');
var winston = require('winston');
var fs = require('fs');

var packageName = require('../package').name;

function logger (opts) {
  if (!opts) opts = {};
  logger.stream = opts.stream || opts.file
    ? fs.createWriteStream(opts.file, {flags: 'a'})
    : null; // no place to log, so throw away
  var winstonLogger = new winston.Logger({
    exitOnError: false,
    transports: !logger.stream ? [] : [
      new winston.transports.File({
        stream: logger.stream,
        level: opts.level || 'info',
        handleExceptions: true,
        json: false,
        prettyPrint: true,
        colorize: true
      })
    ]
  });

  var levels = winston.config.npm.levels;
  if (!(opts.level in levels) || levels[opts.level] > levels.debug) {
    console._error = console.error;
    console.error = function () {
      if (!logger.stream) return;
      logger.stream.write([].join.call(arguments, ' ') + '\n');
    };
  } else {
    require('longjohn');
    require('bluebird').longStackTraces();
  }

  winstonLogger.extend(logger);
  logger._opts = opts;
}

logger();

module.exports = logger;

@@ -127,16 +127,49 @@
 .name;%0A%0A
+console._error = console.error;%0A%0A
 function
@@ -802,44 +802,8 @@
 ) %7B%0A
-    console._error = console.error;%0A
     

move console._error defn out of function