Only log updates to file

This commit is contained in:
Vankka 2024-06-24 02:47:34 +03:00
parent 0e07eb26be
commit f125100b1b
No known key found for this signature in database
GPG Key ID: 62E48025ED4E7EBB
5 changed files with 56 additions and 19 deletions

View File

@ -27,6 +27,7 @@ public enum BanSyncResult implements ISyncResult {
NO_DISCORD_CONNECTION("No Discord connection"), NO_DISCORD_CONNECTION("No Discord connection"),
GUILD_DOESNT_EXIST("Guild doesn't exist"), GUILD_DOESNT_EXIST("Guild doesn't exist"),
INVALID_CONFIG("Invalid config"), INVALID_CONFIG("Invalid config"),
; ;
private final String format; private final String format;
@ -36,7 +37,12 @@ public enum BanSyncResult implements ISyncResult {
} }
@Override @Override
public boolean isSuccess() { public boolean isError() {
return true;
}
@Override
public boolean isUpdate() {
return false; return false;
} }

View File

@ -22,21 +22,34 @@ import com.discordsrv.common.sync.result.ISyncResult;
public enum GroupSyncResult implements ISyncResult { public enum GroupSyncResult implements ISyncResult {
// Fail
NOT_A_GUILD_MEMBER("User is not part of the server the role is in", true),
// Error // Error
ROLE_DOESNT_EXIST("Role doesn't exist"), ROLE_DOESNT_EXIST("Role doesn't exist"),
ROLE_CANNOT_INTERACT("Bot doesn't have a role above the synced role (cannot interact)"), ROLE_CANNOT_INTERACT("Bot doesn't have a role above the synced role (cannot interact)"),
NOT_A_GUILD_MEMBER("User is not part of the server the role is in"),
PERMISSION_BACKEND_FAILED("Failed to interact with permission backend, error printed"), PERMISSION_BACKEND_FAILED("Failed to interact with permission backend, error printed"),
; ;
private final String format; private final String format;
private final boolean success;
GroupSyncResult(String format) { GroupSyncResult(String format) {
this.format = format; this(format, false);
} }
public boolean isSuccess() { GroupSyncResult(String format, boolean success) {
this.format = format;
this.success = success;
}
public boolean isError() {
return !success;
}
@Override
public boolean isUpdate() {
return false; return false;
} }

View File

@ -435,7 +435,7 @@ public abstract class AbstractSyncModule<
if (allFailReason != null) { if (allFailReason != null) {
String reason = allFailReason.format(gameTerm(), discordTerm()); String reason = allFailReason.format(gameTerm(), discordTerm());
String message = "Failed to " + syncName() + " " + summary.who() + " (sync cause: " + summary.cause() + "): " + reason; String message = "Failed to " + syncName() + " " + summary.who() + " (sync cause: " + summary.cause() + "): " + reason;
if (!allFailReason.isSuccess()) { if (allFailReason.isError()) {
logger().error(message, throwableToLog); logger().error(message, throwableToLog);
} else { } else {
logger().debug(message, throwableToLog); logger().debug(message, throwableToLog);
@ -453,14 +453,18 @@ public abstract class AbstractSyncModule<
List<String> successResults = new ArrayList<>(); List<String> successResults = new ArrayList<>();
List<String> failResults = new ArrayList<>(); List<String> failResults = new ArrayList<>();
List<String> auditResults = new ArrayList<>();
for (Map.Entry<ISyncResult, List<String>> entry : groupedResults.entrySet()) { for (Map.Entry<ISyncResult, List<String>> entry : groupedResults.entrySet()) {
ISyncResult result = entry.getKey(); ISyncResult result = entry.getKey();
String line = result.format(gameTerm(), discordTerm()) String line = result.format(gameTerm(), discordTerm())
+ ": [" + String.join(", ", entry.getValue()) + "]"; + ": [" + String.join(", ", entry.getValue()) + "]";
if (result.isSuccess()) { if (result.isError()) {
successResults.add(line);
} else {
failResults.add(line); failResults.add(line);
} else {
successResults.add(line);
}
if (result.isUpdate()) {
auditResults.add(line);
} }
} }
@ -473,7 +477,9 @@ public abstract class AbstractSyncModule<
if (anyFail) { if (anyFail) {
logger().error(syncName() + partially + " failed for " + formatResults(summary, failResults)); logger().error(syncName() + partially + " failed for " + formatResults(summary, failResults));
} }
discordSRV.logger().writeLogForCurrentDay(logFileName(), formatResults(summary, successResults)); if (!auditResults.isEmpty()) {
discordSRV.logger().writeLogForCurrentDay(logFileName(), formatResults(summary, auditResults));
}
}); });
} }

View File

@ -21,17 +21,17 @@ package com.discordsrv.common.sync.result;
public enum GenericSyncResults implements ISyncResult { public enum GenericSyncResults implements ISyncResult {
// Success, actioned // Success, actioned
ADD_DISCORD("Add %d"), ADD_DISCORD("Add %d", true),
REMOVE_DISCORD("Remove %d"), REMOVE_DISCORD("Remove %d", true),
ADD_GAME("Add %g"), ADD_GAME("Add %g", true),
REMOVE_GAME("Remove %g"), REMOVE_GAME("Remove %g", true),
// Success, Nothing done // Success, Nothing done
BOTH_TRUE("Both true"), BOTH_TRUE("Both true"),
BOTH_FALSE("Both false"), BOTH_FALSE("Both false"),
WRONG_DIRECTION("Wrong direction"), WRONG_DIRECTION("Wrong direction"),
// Error // Fail
NOT_LINKED("Accounts not linked"), NOT_LINKED("Accounts not linked"),
; ;
@ -41,20 +41,31 @@ public enum GenericSyncResults implements ISyncResult {
} }
private final String message; private final String message;
private final boolean update;
private final boolean success; private final boolean success;
GenericSyncResults(String message) { GenericSyncResults(String message) {
this(message, true); this(message, false);
} }
GenericSyncResults(String message, boolean success) { GenericSyncResults(String message, boolean update) {
this(message, update, true);
}
GenericSyncResults(String message, boolean update, boolean success) {
this.message = message; this.message = message;
this.update = update;
this.success = success; this.success = success;
} }
@Override @Override
public boolean isSuccess() { public boolean isError() {
return success; return !success;
}
@Override
public boolean isUpdate() {
return update;
} }
@Override @Override

View File

@ -22,7 +22,8 @@ import com.discordsrv.api.placeholder.util.Placeholders;
public interface ISyncResult { public interface ISyncResult {
boolean isSuccess(); boolean isError();
boolean isUpdate();
String getFormat(); String getFormat();
default String format(String gameTerm, String discordTerm) { default String format(String gameTerm, String discordTerm) {