'use strict';

exports.parse = function(log) {
  return require(__dirname + '/parsers').named_capture(
    log,
    ['host', 'user', 'time', 'method', 'path', 'code', 'size', 'referer', 'agent'],
    // From fluentd-0.10.9/lib/fluent/parser.rb:
    /^([^ ]*) [^ ]* ([^ ]*) \[([^\]]*)\] "(\S+)(?: +([^ ]*) +\S*)?" ([^ ]*) ([^ ]*)(?: "([^\"]*)" "([^\"]*)")?$/
  );
};

exports.getPreviewContext = function(log) {
  if (log.code) {
    switch (log.code[0]) {
      case '2': log.codeClass = 'success'; break;
      case '3': log.codeClass = 'info'; break;
      case '4': log.codeClass = 'important'; break;
      case '5': log.codeClass = 'important'; break;
    }
  }

  if (log.referer) {
    log.referer = '-' == log.referer ? '' : log.referer;
    log.referer_min = log.referer.replace(/^http(s)?:\/\//, '');
  }
  return log;
};

@@ -821,12 +821,417 @@
 urn log;%0A%7D;%0A
+%0Aexports.extractTime = function(str) %7B%0A  var matches = str.match(/(%5Cd+)%5C/(%5BA-Za-z%5D+)%5C/(%5Cd%7B4%7D):(%5Cd%7B2%7D:%5Cd%7B2%7D:%5Cd%7B2%7D %5C+%5Cd%7B4%7D)/);%0A  var months = %5B%0A    'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'%0A  %5D;%0A  var parsable = util.format(%0A    '%25d/%25d/%25d %25s',%0A    months.indexOf(matches%5B2%5D) + 1,%0A    matches%5B1%5D,%0A    matches%5B3%5D,%0A    matches%5B4%5D%0A  );%0A  return Date.parse(parsable);%0A%7D;%0A

Add time extraction for nginx access parser.