Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: MMLogger using parametrized message and string formatter #6591

Merged
merged 3 commits into from
Feb 23, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion megamek/src/megamek/MegaMek.java
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public static void main(String... args) {
final String name = t.getClass().getName();
final String message = String.format(MMLoggingConstants.UNHANDLED_EXCEPTION, name);
final String title = String.format(MMLoggingConstants.UNHANDLED_EXCEPTION_TITLE, name);
logger.error(t, message, title);
logger.errorDialog(t, message, title);
});

// Second, let's handle logging
Expand Down
10 changes: 5 additions & 5 deletions megamek/src/megamek/Version.java
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ public void fillFromText(final @Nullable String text) {
final String nullOrBlank = ((text == null) ? "a null string" : "a blank string");
final String message = String.format(MMLoggingConstants.VERSION_ERROR_CANNOT_PARSE_VERSION_FROM_STRING,
nullOrBlank);
logger.fatal(message, MMLoggingConstants.VERSION_PARSE_FAILURE);
logger.fatalDialog(message, MMLoggingConstants.VERSION_PARSE_FAILURE);
return;
}

Expand All @@ -249,31 +249,31 @@ public void fillFromText(final @Nullable String text) {

if ((snapshotSplit.length > 2) || (versionSplit.length < 3)) {
final String message = String.format(MMLoggingConstants.VERSION_ILLEGAL_VERSION_FORMAT, text);
logger.fatal(message, MMLoggingConstants.VERSION_PARSE_FAILURE);
logger.fatalDialog(message, MMLoggingConstants.VERSION_PARSE_FAILURE);
return;
}

try {
setRelease(Integer.parseInt(versionSplit[0]));
} catch (Exception e) {
final String message = String.format(MMLoggingConstants.VERSION_FAILED_TO_PARSE_RELEASE, text);
logger.fatal(e, message, MMLoggingConstants.VERSION_PARSE_FAILURE);
logger.fatalDialog(e, message, MMLoggingConstants.VERSION_PARSE_FAILURE);
return;
}

try {
setMajor(Integer.parseInt(versionSplit[1]));
} catch (Exception e) {
final String message = String.format(MMLoggingConstants.VERSION_FAILED_TO_PARSE_MAJOR, text);
logger.fatal(e, message, MMLoggingConstants.VERSION_PARSE_FAILURE);
logger.fatalDialog(e, message, MMLoggingConstants.VERSION_PARSE_FAILURE);
return;
}

try {
setMinor(Integer.parseInt(versionSplit[2]));
} catch (Exception e) {
final String message = String.format(MMLoggingConstants.VERSION_FAILED_TO_PARSE_MINOR, text);
logger.fatal(e, message, MMLoggingConstants.VERSION_PARSE_FAILURE);
logger.fatalDialog(e, message, MMLoggingConstants.VERSION_PARSE_FAILURE);
return;
}

Expand Down
2 changes: 1 addition & 1 deletion megamek/src/megamek/client/ui/swing/ClientGUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -2250,7 +2250,7 @@ public void printList(ArrayList<Entity> unitList, JButton button) {
// If something goes wrong, probably ProcessBuild.start if anything,
// Make sure to set the button text back to what it started as no matter what.
button.setText(Messages.getString("ChatLounge.butPrintList"));
logger.error(e, "Operation failed", "Error printing unit list");
logger.errorDialog(e, "Operation failed", "Error printing unit list");

}
}
Expand Down
24 changes: 12 additions & 12 deletions megamek/src/megamek/client/ui/swing/MegaMekGUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -442,9 +442,9 @@ public boolean startServer(@Nullable String serverPassword, int port, boolean is
mailProperties.load(propsReader);
mailer = new EmailService(mailProperties);
} catch (Exception ex) {
logger.error(ex,
Messages.getFormattedString("MegaMek.StartServerError", port, ex.getMessage()),
Messages.getString("MegaMek.LoadGameAlert.title"));
logger.errorDialog(ex,
Messages.getFormattedString("MegaMek.StartServerError", port, ex.getMessage()),
Messages.getString("MegaMek.LoadGameAlert.title"));
return false;
}
}
Expand All @@ -457,14 +457,14 @@ public boolean startServer(@Nullable String serverPassword, int port, boolean is
gameManager = getGameManager(gameType);
server = new Server(serverPassword, port, gameManager, isRegister, metaServer, mailer, false);
} catch (Exception ex) {
logger.error(ex,
Messages.getFormattedString("MegaMek.StartServerError", port, ex.getMessage()),
Messages.getString("MegaMek.LoadGameAlert.title"));
logger.errorDialog(ex,
Messages.getFormattedString("MegaMek.StartServerError", port, ex.getMessage()),
Messages.getString("MegaMek.LoadGameAlert.title"));
return false;
}

if (saveGameFile != null && !server.loadGame(saveGameFile)) {
logger.error(Messages.getFormattedString("MegaMek.LoadGameAlert.message", saveGameFile.getAbsolutePath()),
logger.errorDialog(Messages.getFormattedString("MegaMek.LoadGameAlert.message", saveGameFile.getAbsolutePath()),
Messages.getString("MegaMek.LoadGameAlert.title"));
server.die();
server = null;
Expand Down Expand Up @@ -520,7 +520,7 @@ public void startClient(String playerName, String serverAddress, int port, GameT
serverAddress = Server.validateServerAddress(serverAddress);
port = Server.validatePort(port);
} catch (Exception ex) {
logger.error(ex,
logger.errorDialog(ex,
Messages.getFormattedString("MegaMek.ServerConnectionError", serverAddress, port),
Messages.getString("MegaMek.LoadGameAlert.title"));
return;
Expand Down Expand Up @@ -617,7 +617,7 @@ public String getDescription() {
}
}
} catch (Exception ex) {
logger.error(ex,
logger.errorDialog(ex,
Messages.getFormattedString("MegaMek.LoadGameAlert.message",
fc.getSelectedFile().getAbsolutePath()),
Messages.getString("MegaMek.LoadGameAlert.title"));
Expand Down Expand Up @@ -764,15 +764,15 @@ void scenario() {
scenario = sl.load();
game = scenario.createGame();
} catch (Exception e) {
logger.error(e, Messages.getString("MegaMek.HostScenarioAlert.message", e.getMessage()),
logger.errorDialog(e, Messages.getString("MegaMek.HostScenarioAlert.message", e.getMessage()),
Messages.getString("MegaMek.HostScenarioAlert.title"));
return;
}

// popup options dialog
if (!scenario.hasFixedGameOptions() && game instanceof Game twGame) {
GameOptionsDialog god = new GameOptionsDialog(frame, (GameOptions) twGame.getOptions(), false);
god.update((GameOptions) twGame.getOptions());
GameOptionsDialog god = new GameOptionsDialog(frame, twGame.getOptions(), false);
god.update(twGame.getOptions());
god.setEditable(true);
god.setVisible(true);
for (IBasicOption opt : god.getOptions()) {
Expand Down
Loading