diff --git a/src/modes/apache/apacheAnalyzer.h b/src/modes/apache/apacheAnalyzer.h --- a/src/modes/apache/apacheAnalyzer.h +++ b/src/modes/apache/apacheAnalyzer.h @@ -72,6 +72,11 @@ * [Thu May 19 18:00:19 2005] [notice] Digest: generating secret for digest authentication ... * [client 127.0.0.1] PHP Parse error: parse error, unexpected T_PRIVATE, expecting T_STRING in * /mnt/boulot/web/annivernet/src/fonctions/formulaire.inc.php on line 25 + * + * Log line example from Apache 2.4 documentation: + * [Fri Sep 09 10:42:29.902022 2011] [core:error] [pid 35708:tid 4328636416] + * [client 72.15.99.187] File does not exist: + * /usr/local/apache2/htdocs/favicon.ico */ LogLine *parseMessage(const QString &logLine, const LogFile &originalLogFile) Q_DECL_OVERRIDE { @@ -81,55 +86,52 @@ QTime time; QString level; + QString client; - // Temporary variable - int squareBracket; - - // Special case which sometimes happens - if (line.indexOf(QLatin1String("[client")) == 0) { - date = QDate::currentDate(); - time = QTime::currentTime(); - level = QStringLiteral("notice"); - } else { - // The Date - int dateBegin = line.indexOf(QLatin1String("[")); - int dateEnd = line.indexOf(QLatin1String("]")); - - QString type; - QString message; - - QString strDate = line.mid(dateBegin + 1, dateEnd - dateBegin - 1); - - QString month = strDate.mid(4, 3); - - QString day = strDate.mid(8, 2); - - QString hour = strDate.mid(11, 2); - QString min = strDate.mid(14, 2); - QString sec = strDate.mid(17, 2); - - QString year = strDate.mid(20, 4); - - date = QDate(year.toInt(), ParsingHelper::instance()->parseSyslogMonth(month), day.toInt()); - time = QTime(hour.toInt(), min.toInt(), sec.toInt()); + for (int beginSquareBracket; (beginSquareBracket = line.indexOf(QLatin1Char('['))) >= 0; ) { + int endSquareBracket = line.indexOf(QLatin1Char(']'), beginSquareBracket); + if (endSquareBracket < 0) { + break; + } + const QString field = line.mid(beginSquareBracket + 1, endSquareBracket - beginSquareBracket - 1); + line.remove(beginSquareBracket, endSquareBracket - beginSquareBracket + 1); + if (field.isEmpty()) { + continue; + } + + if (field.startsWith(QLatin1String("client "))) { + client = field.mid(7); + } else if (field.startsWith(QLatin1String("pid "))) { + // ignore process ID + } else if (field.at(0).isUpper()) { + // date/time starts with an uppercase letter + if (!date.isValid()) { + // ddd MMM dd hh:mm:ss yyyy + // ddd MMM dd hh:mm:ss.uuuuuu yyyy + date = QDate(field.right(4).toInt(), ParsingHelper::instance()->parseSyslogMonth(field.mid(4, 3)), field.mid(8, 2).toInt()); + time = QTime(field.mid(11, 2).toInt(), field.mid(14, 2).toInt(), field.mid(17, 2).toInt()); + } + } else if (level.isEmpty()) { + // level field starts with a lowercase letter + level = field; + int colonIndex = level.indexOf(QLatin1Char(':')); + if (colonIndex > 0) { + // strip module name + level = level.mid(colonIndex + 1); + } + } + } - line = line.remove(0, dateEnd + 3); + // remaining line is the message text + line = line.simplified(); - // The log level - squareBracket = line.indexOf(QLatin1String("]")); - level = line.left(squareBracket); - line = line.remove(0, squareBracket + 2); + // provide defaults for missing fields + if (level.isEmpty()) { + level = QStringLiteral("notice"); } - - // The client - int beginSquareBracket = line.indexOf(QLatin1String("[client")); - squareBracket = line.indexOf(QLatin1String("]")); - QString client; - if (beginSquareBracket == -1 || squareBracket == -1) { - client = QLatin1String(""); - } else { - client = line.mid(8, squareBracket - 8); // 8=strlen("[client ") - line = line.remove(0, squareBracket + 2); + if (!date.isValid() || !time.isValid()) { + date = QDate::currentDate(); + time = QTime::currentTime(); } QStringList list; @@ -145,9 +147,14 @@ void initializeTypeLevels() { - mapTypeLevels[QStringLiteral("notice")] = Globals::instance().informationLogLevel(); + mapTypeLevels[QStringLiteral("debug")] = Globals::instance().debugLogLevel(); + mapTypeLevels[QStringLiteral("info")] = Globals::instance().informationLogLevel(); + mapTypeLevels[QStringLiteral("notice")] = Globals::instance().noticeLogLevel(); mapTypeLevels[QStringLiteral("warn")] = Globals::instance().warningLogLevel(); mapTypeLevels[QStringLiteral("error")] = Globals::instance().errorLogLevel(); + mapTypeLevels[QStringLiteral("crit")] = Globals::instance().criticalLogLevel(); + mapTypeLevels[QStringLiteral("alert")] = Globals::instance().alertLogLevel(); + mapTypeLevels[QStringLiteral("emerg")] = Globals::instance().emergencyLogLevel(); } LogLevel *findLogLevel(const QString &type)