mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2024-12-27 19:47:49 +01:00
Connection fail log warning should be less common.
This commit is contained in:
parent
3d6c080ac2
commit
9d3def37af
@ -56,7 +56,7 @@ public class ConnectionLog {
|
||||
return log;
|
||||
}
|
||||
|
||||
public static class Entry {
|
||||
public static class Entry implements Comparable<Entry> {
|
||||
|
||||
private final int responseCode;
|
||||
private final long timeSent;
|
||||
@ -73,6 +73,17 @@ public class ConnectionLog {
|
||||
public long getTimeSent() {
|
||||
return timeSent;
|
||||
}
|
||||
|
||||
/**
|
||||
* Most recent first.
|
||||
*
|
||||
* @param o
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public int compareTo(Entry o) {
|
||||
return -Long.compare(this.timeSent, o.timeSent);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -7,6 +7,11 @@ package com.djrapitops.plan.system.info.connection;
|
||||
import com.djrapitops.plan.api.exceptions.connection.*;
|
||||
import com.djrapitops.plugin.api.utility.log.Log;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Class that decides what to do with WebExceptions.
|
||||
*
|
||||
@ -17,7 +22,11 @@ public class WebExceptionLogger {
|
||||
public static void logIfOccurs(Class c, ExceptionLoggingAction action) {
|
||||
try {
|
||||
action.performAction();
|
||||
} catch (ConnectionFailException | UnsupportedTransferDatabaseException | UnauthorizedServerException
|
||||
} catch (ConnectionFailException e) {
|
||||
if (shouldLog(e)) {
|
||||
Log.warn(e.getMessage());
|
||||
}
|
||||
} catch (UnsupportedTransferDatabaseException | UnauthorizedServerException
|
||||
| NotFoundException | NoServersException e) {
|
||||
Log.warn(e.getMessage());
|
||||
} catch (WebException e) {
|
||||
@ -25,6 +34,27 @@ public class WebExceptionLogger {
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean shouldLog(ConnectionFailException e) {
|
||||
String address = null;
|
||||
if (e.getMessage().contains("to address")) {
|
||||
String[] split = e.getMessage().split("to address: ");
|
||||
if (split.length == 2) {
|
||||
String[] split2 = split[1].split("<br>");
|
||||
if (split2.length == 2) {
|
||||
address = split2[0];
|
||||
}
|
||||
}
|
||||
}
|
||||
Map<String, Map<String, ConnectionLog.Entry>> logEntries = ConnectionLog.getLogEntries();
|
||||
Map<String, ConnectionLog.Entry> entries = logEntries.get("Out: " + address);
|
||||
if (entries != null) {
|
||||
List<ConnectionLog.Entry> connections = new ArrayList<>(entries.values());
|
||||
Collections.sort(connections);
|
||||
return connections.isEmpty() || connections.get(0).getResponseCode() != -1;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public interface ExceptionLoggingAction {
|
||||
|
||||
void performAction() throws WebException;
|
||||
|
Loading…
Reference in New Issue
Block a user