mirror of
https://github.com/eclipse-sailing-analytics/sailing-analytics.git
synced 2026-09-18 11:49:09 +00:00
relax Apache log analysis by issuing warnings for unparseable dates instead of aborting
This commit is contained in:
@@ -5,6 +5,7 @@ import java.net.UnknownHostException;
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Iterator;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import com.sap.sse.common.TimePoint;
|
||||
import com.sap.sse.common.Util;
|
||||
@@ -21,6 +22,7 @@ import com.sap.sse.common.impl.MillisecondsTimePoint;
|
||||
*
|
||||
*/
|
||||
public class LogEntry {
|
||||
private static final Logger logger = Logger.getLogger(LogEntry.class.getName());
|
||||
private final SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MMM/yyyy:HH:mm:ss ZZZZZ");
|
||||
|
||||
private final String hostname;
|
||||
@@ -79,7 +81,15 @@ public class LogEntry {
|
||||
* "15/Dec/2017:16:49:41 +0000" will result in "15/Dec/2017".
|
||||
*/
|
||||
public String getDateString() {
|
||||
return getTimestampString().substring(0, getTimestampString().indexOf(':'));
|
||||
final String result;
|
||||
final int indexOfColon = getTimestampString().indexOf(':');
|
||||
if (indexOfColon < 0) {
|
||||
logger.warning("Couldn't find : as date separator in what was expected to be a date string: "+getTimestampString());
|
||||
result = null;
|
||||
} else {
|
||||
result = getTimestampString().substring(0, indexOfColon);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public TimePoint getTimepoint() throws ParseException {
|
||||
|
||||
@@ -341,7 +341,12 @@ public class UniqueIPsPerReferrer {
|
||||
final LogEntry entry = new LogEntry(line);
|
||||
final String hostname = entry.getHostname();
|
||||
final Writer fileWriterForHostname = getFileWriter(hostname, fileWritersPerHostname, this::getHostnameSpecificFile, /* gzipCompressed */ false, /* append */ true);
|
||||
fileWriterForHostname.write(entry.getRequestorIpString()+" "+entry.getDateString()+" "+entry.getUserAgent()+"\n");
|
||||
final String dateString = entry.getDateString();
|
||||
final String requestorIpString = entry.getRequestorIpString();
|
||||
final String userAgent = entry.getUserAgent();
|
||||
if (dateString != null && requestorIpString != null && userAgent != null) {
|
||||
fileWriterForHostname.write(requestorIpString+" "+dateString+" "+userAgent+"\n");
|
||||
}
|
||||
}
|
||||
for (final Writer fw : fileWritersPerHostname.values()) {
|
||||
fw.close();
|
||||
|
||||
Reference in New Issue
Block a user