Improved code.

This commit is contained in:
Christian P. MOMON 2021-02-20 02:01:24 +01:00
parent 4ee90a3671
commit 5e4829d315

View file

@ -222,13 +222,11 @@ public class HttpAccessLogAnalyzer
* the line * the line
* @return the http log * @return the http log
*/ */
public static HttpAccessLog parseLog(final String line, final String pattern) public static HttpAccessLog parseLog(final String line, final Pattern pattern)
{ {
HttpAccessLog result; HttpAccessLog result;
Pattern combined = Pattern.compile(pattern); Matcher matcher = pattern.matcher(line);
Matcher matcher = combined.matcher(line);
if (matcher.matches()) if (matcher.matches())
{ {
result = new HttpAccessLog(); result = new HttpAccessLog();
@ -266,7 +264,9 @@ public class HttpAccessLogAnalyzer
// '"$http_referer" "$http_user_agent"'; // '"$http_referer" "$http_user_agent"';
String combinedPattern = "^(?<remoteAddress>[a-zA-F0-9\\\\:\\\\.]+) - (?<remoteUser>\\S+) \\[(?<time>[^\\]]+)\\] \"(?<request>[^\"]*)\" (?<status>\\d+) (?<bodyBytesSent>\\d+) \"(?<referer>[^\"]*)\" \"(?<userAgent>[^\"]*)\".*$"; String combinedPattern = "^(?<remoteAddress>[a-zA-F0-9\\\\:\\\\.]+) - (?<remoteUser>\\S+) \\[(?<time>[^\\]]+)\\] \"(?<request>[^\"]*)\" (?<status>\\d+) (?<bodyBytesSent>\\d+) \"(?<referer>[^\"]*)\" \"(?<userAgent>[^\"]*)\".*$";
result = parseLog(line, combinedPattern); Pattern pattern = Pattern.compile(combinedPattern);
result = parseLog(line, pattern);
// //
return result; return result;