/* automatically generated by JSCoverage - do not edit */
if (typeof _$jscoverage === 'undefined') _$jscoverage = {};
if (! _$jscoverage['connect-logger.js']) {
  _$jscoverage['connect-logger.js'] = [];
  _$jscoverage['connect-logger.js'][1] = 0;
  _$jscoverage['connect-logger.js'][2] = 0;
  _$jscoverage['connect-logger.js'][3] = 0;
  _$jscoverage['connect-logger.js'][34] = 0;
  _$jscoverage['connect-logger.js'][35] = 0;
  _$jscoverage['connect-logger.js'][36] = 0;
  _$jscoverage['connect-logger.js'][37] = 0;
  _$jscoverage['connect-logger.js'][38] = 0;
  _$jscoverage['connect-logger.js'][40] = 0;
  _$jscoverage['connect-logger.js'][43] = 0;
  _$jscoverage['connect-logger.js'][48] = 0;
  _$jscoverage['connect-logger.js'][50] = 0;
  _$jscoverage['connect-logger.js'][53] = 0;
  _$jscoverage['connect-logger.js'][54] = 0;
  _$jscoverage['connect-logger.js'][56] = 0;
  _$jscoverage['connect-logger.js'][63] = 0;
  _$jscoverage['connect-logger.js'][66] = 0;
  _$jscoverage['connect-logger.js'][67] = 0;
  _$jscoverage['connect-logger.js'][68] = 0;
  _$jscoverage['connect-logger.js'][69] = 0;
  _$jscoverage['connect-logger.js'][70] = 0;
  _$jscoverage['connect-logger.js'][73] = 0;
  _$jscoverage['connect-logger.js'][74] = 0;
  _$jscoverage['connect-logger.js'][75] = 0;
  _$jscoverage['connect-logger.js'][76] = 0;
  _$jscoverage['connect-logger.js'][78] = 0;
  _$jscoverage['connect-logger.js'][83] = 0;
  _$jscoverage['connect-logger.js'][84] = 0;
  _$jscoverage['connect-logger.js'][85] = 0;
  _$jscoverage['connect-logger.js'][86] = 0;
  _$jscoverage['connect-logger.js'][87] = 0;
  _$jscoverage['connect-logger.js'][88] = 0;
  _$jscoverage['connect-logger.js'][89] = 0;
  _$jscoverage['connect-logger.js'][90] = 0;
  _$jscoverage['connect-logger.js'][92] = 0;
  _$jscoverage['connect-logger.js'][99] = 0;
  _$jscoverage['connect-logger.js'][113] = 0;
  _$jscoverage['connect-logger.js'][114] = 0;
  _$jscoverage['connect-logger.js'][134] = 0;
  _$jscoverage['connect-logger.js'][136] = 0;
  _$jscoverage['connect-logger.js'][169] = 0;
  _$jscoverage['connect-logger.js'][170] = 0;
  _$jscoverage['connect-logger.js'][172] = 0;
  _$jscoverage['connect-logger.js'][173] = 0;
  _$jscoverage['connect-logger.js'][174] = 0;
  _$jscoverage['connect-logger.js'][177] = 0;
  _$jscoverage['connect-logger.js'][178] = 0;
  _$jscoverage['connect-logger.js'][181] = 0;
  _$jscoverage['connect-logger.js'][182] = 0;
  _$jscoverage['connect-logger.js'][184] = 0;
  _$jscoverage['connect-logger.js'][187] = 0;
  _$jscoverage['connect-logger.js'][191] = 0;
  _$jscoverage['connect-logger.js'][194] = 0;
}
_$jscoverage['connect-logger.js'][1]++;
"use strict";
_$jscoverage['connect-logger.js'][2]++;
var levels = require("./levels");
_$jscoverage['connect-logger.js'][3]++;
var DEFAULT_FORMAT = ":remote-addr - - \":method :url HTTP/:http-version\" :status :content-length \":referrer\" \":userstate-agent\"";
_$jscoverage['connect-logger.js'][34]++;
function getLogger(logger4js, options) {
  _$jscoverage['connect-logger.js'][35]++;
  if ("object" == typeof options) {
    _$jscoverage['connect-logger.js'][36]++;
    options = options || {};
  }
  else {
    _$jscoverage['connect-logger.js'][37]++;
    if (options) {
      _$jscoverage['connect-logger.js'][38]++;
      options = {format: options};
    }
    else {
      _$jscoverage['connect-logger.js'][40]++;
      options = {};
    }
  }
  _$jscoverage['connect-logger.js'][43]++;
  var thislogger = logger4js, level = levels.toLevel(options.level, levels.INFO), fmt = options.format || DEFAULT_FORMAT, nolog = options.nolog? createNoLogCondition(options.nolog): null;
  _$jscoverage['connect-logger.js'][48]++;
  return (function (req, res, next) {
  _$jscoverage['connect-logger.js'][50]++;
  if (req._logging) {
    _$jscoverage['connect-logger.js'][50]++;
    return next();
  }
  _$jscoverage['connect-logger.js'][53]++;
  if (nolog && nolog.test(req.originalUrl)) {
    _$jscoverage['connect-logger.js'][53]++;
    return next();
  }
  _$jscoverage['connect-logger.js'][54]++;
  if (thislogger.isLevelEnabled(level) || options.level === "auto") {
    _$jscoverage['connect-logger.js'][56]++;
    var start = new Date(), statusCode, writeHead = res.writeHead, end = res.end, url = req.originalUrl;
    _$jscoverage['connect-logger.js'][63]++;
    req._logging = true;
    _$jscoverage['connect-logger.js'][66]++;
    res.writeHead = (function (code, headers) {
  _$jscoverage['connect-logger.js'][67]++;
  res.writeHead = writeHead;
  _$jscoverage['connect-logger.js'][68]++;
  res.writeHead(code, headers);
  _$jscoverage['connect-logger.js'][69]++;
  res.__statusCode = statusCode = code;
  _$jscoverage['connect-logger.js'][70]++;
  res.__headers = headers || {};
  _$jscoverage['connect-logger.js'][73]++;
  if (options.level === "auto") {
    _$jscoverage['connect-logger.js'][74]++;
    level = levels.INFO;
    _$jscoverage['connect-logger.js'][75]++;
    if (code >= 300) {
      _$jscoverage['connect-logger.js'][75]++;
      level = levels.WARN;
    }
    _$jscoverage['connect-logger.js'][76]++;
    if (code >= 400) {
      _$jscoverage['connect-logger.js'][76]++;
      level = levels.ERROR;
    }
  }
  else {
    _$jscoverage['connect-logger.js'][78]++;
    level = levels.toLevel(options.level, levels.INFO);
  }
});
    _$jscoverage['connect-logger.js'][83]++;
    res.end = (function (chunk, encoding) {
  _$jscoverage['connect-logger.js'][84]++;
  res.end = end;
  _$jscoverage['connect-logger.js'][85]++;
  res.end(chunk, encoding);
  _$jscoverage['connect-logger.js'][86]++;
  res.responseTime = new Date() - start;
  _$jscoverage['connect-logger.js'][87]++;
  if (thislogger.isLevelEnabled(level)) {
    _$jscoverage['connect-logger.js'][88]++;
    if (typeof fmt === "function") {
      _$jscoverage['connect-logger.js'][89]++;
      var line = fmt(req, res, (function (str) {
  _$jscoverage['connect-logger.js'][89]++;
  return format(str, req, res);
}));
      _$jscoverage['connect-logger.js'][90]++;
      if (line) {
        _$jscoverage['connect-logger.js'][90]++;
        thislogger.log(level, line);
      }
    }
    else {
      _$jscoverage['connect-logger.js'][92]++;
      thislogger.log(level, format(fmt, req, res));
    }
  }
});
  }
  _$jscoverage['connect-logger.js'][99]++;
  next();
});
}
_$jscoverage['connect-logger.js'][113]++;
function format(str, req, res) {
  _$jscoverage['connect-logger.js'][114]++;
  return str.replace(":url", req.originalUrl).replace(":method", req.method).replace(":status", res.__statusCode || res.statusCode).replace(":response-time", res.responseTime).replace(":date", new Date().toUTCString()).replace(":referrer", req.headers.referer || req.headers.referrer || "").replace(":http-version", req.httpVersionMajor + "." + req.httpVersionMinor).replace(":remote-addr", req.socket && (req.socket.remoteAddress || (req.socket.socket && req.socket.socket.remoteAddress))).replace(":userstate-agent", req.headers["userstate-agent"] || "").replace(":content-length", (res._headers && res._headers["content-length"]) || (res.__headers && res.__headers["Content-Length"]) || "-").replace(/:req\[([^\]]+)\]/g, (function (_, field) {
  _$jscoverage['connect-logger.js'][134]++;
  return req.headers[field.toLowerCase()];
})).replace(/:res\[([^\]]+)\]/g, (function (_, field) {
  _$jscoverage['connect-logger.js'][136]++;
  return res._headers? (res._headers[field.toLowerCase()] || res.__headers[field]): (res.__headers && res.__headers[field]);
}));
}
_$jscoverage['connect-logger.js'][169]++;
function createNoLogCondition(nolog) {
  _$jscoverage['connect-logger.js'][170]++;
  var regexp = null;
  _$jscoverage['connect-logger.js'][172]++;
  if (nolog) {
    _$jscoverage['connect-logger.js'][173]++;
    if (nolog instanceof RegExp) {
      _$jscoverage['connect-logger.js'][174]++;
      regexp = nolog;
    }
    _$jscoverage['connect-logger.js'][177]++;
    if (typeof nolog === "string") {
      _$jscoverage['connect-logger.js'][178]++;
      regexp = new RegExp(nolog);
    }
    _$jscoverage['connect-logger.js'][181]++;
    if (Array.isArray(nolog)) {
      _$jscoverage['connect-logger.js'][182]++;
      var regexpsAsStrings = nolog.map((function convertToStrings(o) {
  _$jscoverage['connect-logger.js'][184]++;
  return o.source? o.source: o;
}));
      _$jscoverage['connect-logger.js'][187]++;
      regexp = new RegExp(regexpsAsStrings.join("|"));
    }
  }
  _$jscoverage['connect-logger.js'][191]++;
  return regexp;
}
_$jscoverage['connect-logger.js'][194]++;
exports.connectLogger = getLogger;
_$jscoverage['connect-logger.js'].source = ["\"use strict\";","var levels = require(\"./levels\");","var DEFAULT_FORMAT = ':remote-addr - -' + ","  ' \":method :url HTTP/:http-version\"' + ","  ' :status :content-length \":referrer\"' + ","  ' \":userstate-agent\"';","/**"," * Log requests with the given `options` or a `format` string."," *"," * Options:"," *"," *   - `format`        Format string, see below for tokens"," *   - `level`         A log4js levels instance. Supports also 'auto'"," *"," * Tokens:"," *"," *   - `:req[header]` ex: `:req[Accept]`"," *   - `:res[header]` ex: `:res[Content-Length]`"," *   - `:http-version`"," *   - `:response-time`"," *   - `:remote-addr`"," *   - `:date`"," *   - `:method`"," *   - `:url`"," *   - `:referrer`"," *   - `:userstate-agent`"," *   - `:status`"," *"," * @param {String|Function|Object} format or options"," * @return {Function}"," * @api public"," */","","function getLogger(logger4js, options) {","\tif ('object' == typeof options) {","\t\toptions = options || {};","\t} else if (options) {","\t\toptions = { format: options };","\t} else {","\t\toptions = {};","\t}","","\tvar thislogger = logger4js","  , level = levels.toLevel(options.level, levels.INFO)","  , fmt = options.format || DEFAULT_FORMAT","  , nolog = options.nolog ? createNoLogCondition(options.nolog) : null;","","  return function (req, res, next) {","    // mount safety","    if (req._logging) return next();","","\t\t// nologs","\t\tif (nolog &amp;&amp; nolog.test(req.originalUrl)) return next();","\t\tif (thislogger.isLevelEnabled(level) || options.level === 'auto') {","      ","\t\t\tvar start = new Date()","\t\t\t, statusCode","\t\t\t, writeHead = res.writeHead","\t\t\t, end = res.end","\t\t\t, url = req.originalUrl;","","\t\t\t// flag as logging","\t\t\treq._logging = true;","      ","\t\t\t// proxy for statusCode.","\t\t\tres.writeHead = function(code, headers){","\t\t\t\tres.writeHead = writeHead;","\t\t\t\tres.writeHead(code, headers);","\t\t\t\tres.__statusCode = statusCode = code;","\t\t\t\tres.__headers = headers || {};","","\t\t\t\t//status code response level handling","\t\t\t\tif(options.level === 'auto'){","\t\t\t\t\tlevel = levels.INFO;","\t\t\t\t\tif(code &gt;= 300) level = levels.WARN;","\t\t\t\t\tif(code &gt;= 400) level = levels.ERROR;","\t\t\t\t} else {","\t\t\t\t\tlevel = levels.toLevel(options.level, levels.INFO);","\t\t\t\t}","\t\t\t};","      ","\t\t\t// proxy end to output a line to the provided logger.","\t\t\tres.end = function(chunk, encoding) {","\t\t\t\tres.end = end;","\t\t\t\tres.end(chunk, encoding);","\t\t\t\tres.responseTime = new Date() - start;","\t\t\t\tif (thislogger.isLevelEnabled(level)) {","\t\t\t\t\tif (typeof fmt === 'function') {","\t\t\t\t\t\tvar line = fmt(req, res, function(str){ return format(str, req, res); });","\t\t\t\t\t\tif (line) thislogger.log(level, line);","\t\t\t\t\t} else {","\t\t\t\t\t\tthislogger.log(level, format(fmt, req, res));","\t\t\t\t\t}","\t\t\t\t}","\t\t\t};","\t\t}","    ","    //ensure next gets always called","    next();","  };","}","","/**"," * Return formatted log line."," *"," * @param  {String} str"," * @param  {IncomingMessage} req"," * @param  {ServerResponse} res"," * @return {String}"," * @api private"," */","","function format(str, req, res) {","\treturn str","    .replace(':url', req.originalUrl)","    .replace(':method', req.method)","    .replace(':status', res.__statusCode || res.statusCode)","    .replace(':response-time', res.responseTime)","    .replace(':date', new Date().toUTCString())","    .replace(':referrer', req.headers.referer || req.headers.referrer || '')","    .replace(':http-version', req.httpVersionMajor + '.' + req.httpVersionMinor)","    .replace(","      ':remote-addr', ","      req.socket &amp;&amp; ","        (req.socket.remoteAddress || (req.socket.socket &amp;&amp; req.socket.socket.remoteAddress))","    )","    .replace(':userstate-agent', req.headers['userstate-agent'] || '')","    .replace(","      ':content-length', ","      (res._headers &amp;&amp; res._headers['content-length']) || ","        (res.__headers &amp;&amp; res.__headers['Content-Length']) || ","        '-'","    )","    .replace(/:req\\[([^\\]]+)\\]/g, function(_, field){ return req.headers[field.toLowerCase()]; })","    .replace(/:res\\[([^\\]]+)\\]/g, function(_, field){","      return res._headers ? ","        (res._headers[field.toLowerCase()] || res.__headers[field])","        : (res.__headers &amp;&amp; res.__headers[field]);","    });","}","","/**"," * Return RegExp Object about nolog"," *"," * @param  {String} nolog"," * @return {RegExp}"," * @api private"," *"," * syntax"," *  1. String"," *   1.1 \"\\\\.gif\""," *         NOT LOGGING http://example.com/hoge.gif and http://example.com/hoge.gif?fuga"," *         LOGGING http://example.com/hoge.agif"," *   1.2 in \"\\\\.gif|\\\\.jpg$\""," *         NOT LOGGING http://example.com/hoge.gif and "," *           http://example.com/hoge.gif?fuga and http://example.com/hoge.jpg?fuga"," *         LOGGING http://example.com/hoge.agif, "," *           http://example.com/hoge.ajpg and http://example.com/hoge.jpg?hoge"," *   1.3 in \"\\\\.(gif|jpe?g|png)$\""," *         NOT LOGGING http://example.com/hoge.gif and http://example.com/hoge.jpeg"," *         LOGGING http://example.com/hoge.gif?uid=2 and http://example.com/hoge.jpg?pid=3"," *  2. RegExp"," *   2.1 in /\\.(gif|jpe?g|png)$/"," *         SAME AS 1.3"," *  3. Array"," *   3.1 [\"\\\\.jpg$\", \"\\\\.png\", \"\\\\.gif\"]"," *         SAME AS \"\\\\.jpg|\\\\.png|\\\\.gif\""," */","function createNoLogCondition(nolog) {","  var regexp = null;","","\tif (nolog) {","    if (nolog instanceof RegExp) {","      regexp = nolog;","    } ","    ","    if (typeof nolog === 'string') {","      regexp = new RegExp(nolog);","    }","    ","    if (Array.isArray(nolog)) {","      var regexpsAsStrings = nolog.map(","        function convertToStrings(o) { ","          return o.source ? o.source : o;","        }","      );","      regexp = new RegExp(regexpsAsStrings.join('|'));","    }","  }","","  return regexp;","}","","exports.connectLogger = getLogger;"];
