Changeset View
Changeset View
Standalone View
Standalone View
src/modes/apache/apacheAnalyzer.h
Context not available. | |||||
72 | * [Thu May 19 18:00:19 2005] [notice] Digest: generating secret for digest authentication ... | 72 | * [Thu May 19 18:00:19 2005] [notice] Digest: generating secret for digest authentication ... | ||
---|---|---|---|---|---|
73 | * [client 127.0.0.1] PHP Parse error: parse error, unexpected T_PRIVATE, expecting T_STRING in | 73 | * [client 127.0.0.1] PHP Parse error: parse error, unexpected T_PRIVATE, expecting T_STRING in | ||
74 | * /mnt/boulot/web/annivernet/src/fonctions/formulaire.inc.php on line 25 | 74 | * /mnt/boulot/web/annivernet/src/fonctions/formulaire.inc.php on line 25 | ||
75 | * | ||||
76 | * Log line example from Apache 2.4 documentation: | ||||
77 | * [Fri Sep 09 10:42:29.902022 2011] [core:error] [pid 35708:tid 4328636416] | ||||
78 | * [client 72.15.99.187] File does not exist: | ||||
79 | * /usr/local/apache2/htdocs/favicon.ico | ||||
75 | */ | 80 | */ | ||
76 | LogLine *parseMessage(const QString &logLine, const LogFile &originalLogFile) Q_DECL_OVERRIDE | 81 | LogLine *parseMessage(const QString &logLine, const LogFile &originalLogFile) Q_DECL_OVERRIDE | ||
77 | { | 82 | { | ||
Context not available. | |||||
81 | QTime time; | 86 | QTime time; | ||
82 | 87 | | |||
83 | QString level; | 88 | QString level; | ||
89 | QString client; | ||||
84 | 90 | | |||
85 | // Temporary variable | 91 | for (int beginSquareBracket; (beginSquareBracket = line.indexOf(QLatin1Char('['))) >= 0; ) { | ||
86 | int squareBracket; | 92 | int endSquareBracket = line.indexOf(QLatin1Char(']'), beginSquareBracket); | ||
87 | 93 | if (endSquareBracket < 0) { | |||
88 | // Special case which sometimes happens | 94 | break; | ||
89 | if (line.indexOf(QLatin1String("[client")) == 0) { | 95 | } | ||
90 | date = QDate::currentDate(); | 96 | const QString field = line.mid(beginSquareBracket + 1, endSquareBracket - beginSquareBracket - 1); | ||
91 | time = QTime::currentTime(); | 97 | line.remove(beginSquareBracket, endSquareBracket - beginSquareBracket + 1); | ||
92 | level = QStringLiteral("notice"); | 98 | if (field.isEmpty()) { | ||
93 | } else { | 99 | continue; | ||
94 | // The Date | 100 | } | ||
95 | int dateBegin = line.indexOf(QLatin1String("[")); | 101 | | ||
96 | int dateEnd = line.indexOf(QLatin1String("]")); | 102 | if (field.startsWith(QLatin1String("client "))) { | ||
97 | 103 | client = field.mid(7); | |||
98 | QString type; | 104 | } else if (field.startsWith(QLatin1String("pid "))) { | ||
99 | QString message; | 105 | // ignore process ID | ||
100 | 106 | } else if (field.at(0).isUpper()) { | |||
101 | QString strDate = line.mid(dateBegin + 1, dateEnd - dateBegin - 1); | 107 | // date/time starts with an uppercase letter | ||
102 | 108 | if (!date.isValid()) { | |||
103 | QString month = strDate.mid(4, 3); | 109 | // ddd MMM dd hh:mm:ss yyyy | ||
104 | 110 | // ddd MMM dd hh:mm:ss.uuuuuu yyyy | |||
105 | QString day = strDate.mid(8, 2); | 111 | date = QDate(field.right(4).toInt(), ParsingHelper::instance()->parseSyslogMonth(field.mid(4, 3)), field.mid(8, 2).toInt()); | ||
106 | 112 | time = QTime(field.mid(11, 2).toInt(), field.mid(14, 2).toInt(), field.mid(17, 2).toInt()); | |||
107 | QString hour = strDate.mid(11, 2); | 113 | } | ||
108 | QString min = strDate.mid(14, 2); | 114 | } else if (level.isEmpty()) { | ||
109 | QString sec = strDate.mid(17, 2); | 115 | // level field starts with a lowercase letter | ||
110 | 116 | level = field; | |||
111 | QString year = strDate.mid(20, 4); | 117 | int colonIndex = level.indexOf(QLatin1Char(':')); | ||
112 | 118 | if (colonIndex > 0) { | |||
113 | date = QDate(year.toInt(), ParsingHelper::instance()->parseSyslogMonth(month), day.toInt()); | 119 | // strip module name | ||
114 | time = QTime(hour.toInt(), min.toInt(), sec.toInt()); | 120 | level = level.mid(colonIndex + 1); | ||
121 | } | ||||
122 | } | ||||
123 | } | ||||
115 | 124 | | |||
116 | line = line.remove(0, dateEnd + 3); | 125 | // remaining line is the message text | ||
126 | line = line.simplified(); | ||||
117 | 127 | | |||
118 | // The log level | 128 | // provide defaults for missing fields | ||
119 | squareBracket = line.indexOf(QLatin1String("]")); | 129 | if (level.isEmpty()) { | ||
120 | level = line.left(squareBracket); | 130 | level = QStringLiteral("notice"); | ||
121 | line = line.remove(0, squareBracket + 2); | | |||
122 | } | 131 | } | ||
123 | 132 | if (!date.isValid() || !time.isValid()) { | |||
124 | // The client | 133 | date = QDate::currentDate(); | ||
125 | int beginSquareBracket = line.indexOf(QLatin1String("[client")); | 134 | time = QTime::currentTime(); | ||
126 | squareBracket = line.indexOf(QLatin1String("]")); | | |||
127 | QString client; | | |||
128 | if (beginSquareBracket == -1 || squareBracket == -1) { | | |||
129 | client = QLatin1String(""); | | |||
130 | } else { | | |||
131 | client = line.mid(8, squareBracket - 8); // 8=strlen("[client ") | | |||
132 | line = line.remove(0, squareBracket + 2); | | |||
133 | } | 135 | } | ||
134 | 136 | | |||
135 | QStringList list; | 137 | QStringList list; | ||
Context not available. | |||||
145 | 147 | | |||
146 | void initializeTypeLevels() | 148 | void initializeTypeLevels() | ||
147 | { | 149 | { | ||
148 | mapTypeLevels[QStringLiteral("notice")] = Globals::instance().informationLogLevel(); | 150 | mapTypeLevels[QStringLiteral("debug")] = Globals::instance().debugLogLevel(); | ||
151 | mapTypeLevels[QStringLiteral("info")] = Globals::instance().informationLogLevel(); | ||||
152 | mapTypeLevels[QStringLiteral("notice")] = Globals::instance().noticeLogLevel(); | ||||
149 | mapTypeLevels[QStringLiteral("warn")] = Globals::instance().warningLogLevel(); | 153 | mapTypeLevels[QStringLiteral("warn")] = Globals::instance().warningLogLevel(); | ||
150 | mapTypeLevels[QStringLiteral("error")] = Globals::instance().errorLogLevel(); | 154 | mapTypeLevels[QStringLiteral("error")] = Globals::instance().errorLogLevel(); | ||
155 | mapTypeLevels[QStringLiteral("crit")] = Globals::instance().criticalLogLevel(); | ||||
156 | mapTypeLevels[QStringLiteral("alert")] = Globals::instance().alertLogLevel(); | ||||
157 | mapTypeLevels[QStringLiteral("emerg")] = Globals::instance().emergencyLogLevel(); | ||||
151 | } | 158 | } | ||
152 | 159 | | |||
153 | LogLevel *findLogLevel(const QString &type) | 160 | LogLevel *findLogLevel(const QString &type) | ||
Context not available. |