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

Improved Initial Log Message #3412

Merged
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
1 change: 0 additions & 1 deletion megamek/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,6 @@ task stageFiles {

doLast {
mkdir "${fileStagingDir}/${log}"
ant.touch(file: "${fileStagingDir}/${log}/timestamp")
}
}

Expand Down
4 changes: 0 additions & 4 deletions megamek/i18n/megamek/client/messages.properties
Original file line number Diff line number Diff line change
Expand Up @@ -743,11 +743,7 @@ ClientGUI.PointBlankShot.Title=Take pointblank shot?

CommonAboutDialog.about=MegaMek is community effort to implement the Classic BattleTech rules in an\noperating-system-agnostic, network enabled manner. MegaMek is distributed\r\nunder the GNU General Public License. A copy of the license should be available\n in the installation directory. If you've enjoyed playing MegaMek, please share\nit with a friend. If you'd like to improve it, please be aware that your contributions\nmust ALSO be distributed under the GNU General Public License, Version 2 or later.\n
CommonAboutDialog.copyright=MegaMek Copyright 2000-2005 Ben Mazur\n\nBattleTech, BattleMech, 'Mech, and MechWarrior are registered trademarks of\r\nWizKids, LLC. Original BattleTech material Copyright by WizKids, LLC.\nAll Rights Reserved. Used without permission.
CommonAboutDialog.javaVendor=\nJava Vendor\u0020
CommonAboutDialog.javaVersion=\nJava Version\u0020
CommonAboutDialog.timestamp=\nTimestamp\u0020
CommonAboutDialog.title=About MegaMek
CommonAboutDialog.version=MegaMek Version\u0020

#In-game Button Captions
CommonMenuBar.Active=Active({0})
Expand Down
6 changes: 1 addition & 5 deletions megamek/i18n/megamek/client/messages_de.properties
Original file line number Diff line number Diff line change
Expand Up @@ -240,13 +240,9 @@ ClientGUI.TransmittingData=Spieldaten werden übertragen...
ClientGUI.viewMenuItem=Ansehen
ClientGUI.waitingOnTheServer=Warte auf Server...

CommonAboutDialog.about=MegaMek ist ein Versuch, die Regeln von Classic Battletech in\neinem Betriebssystem-Unabhängigen, Netzwerkfähigen Programm umzusetzen.\nMegaMek wird unter den Regeln der GNU General Public License vertrieben.\nEine Kopie dieser Lizenz sollte im Installationsverzeichnis vorhanden sein.\nWenn Sie mit MegaMek zufrieden sind, geben Sie es an Freunde weiter. Wenn Sie Verbesserungen implementieren, so müssen diese ebenfalls unter der GPL, Version 2 oder neuer, weitergegeben werden.
CommonAboutDialog.about=MegaMek ist ein Versuch, die Regeln von Classic BattleTech in\neinem Betriebssystem-Unabhängigen, Netzwerkfähigen Programm umzusetzen.\nMegaMek wird unter den Regeln der GNU General Public License vertrieben.\nEine Kopie dieser Lizenz sollte im Installationsverzeichnis vorhanden sein.\nWenn Sie mit MegaMek zufrieden sind, geben Sie es an Freunde weiter. Wenn Sie Verbesserungen implementieren, so müssen diese ebenfalls unter der GPL, Version 2 oder neuer, weitergegeben werden.
CommonAboutDialog.copyright=MegaMek Copyright 2000-2005 Ben Mazur\n\nBattleTech, BattleMech, 'Mech, and MechWarrior are registered trademarks of\r\nWizKids, LLC. Original BattleTech material Copyright by WizKids, LLC.\nAll Rights Reserved. Used without permission.
CommonAboutDialog.javaVendor=\nJava Vendor\u0020
CommonAboutDialog.javaVersion=\nJava Version\u0020
CommonAboutDialog.timestamp=\nTimestamp\u0020
CommonAboutDialog.title=Über MegaMek
CommonAboutDialog.version=MegaMek Version\u0020

CommonMenuBar.BoardMenu=Karte
CommonMenuBar.Command=Befehl({0})
Expand Down
4 changes: 0 additions & 4 deletions megamek/i18n/megamek/client/messages_ru.properties
Original file line number Diff line number Diff line change
Expand Up @@ -376,11 +376,7 @@ ClientGUI.doneMenuItem=Готово
ClientGUI.waitingOnTheServer=Ожидание на сервере...
CommonAboutDialog.about=МегаМек - общественная попытка применить классические правила Battletech в \n сетевой манере, независимой от операционной системы. МегаМек распространяется\r\nчерез лицензию GNU. Копия лицензии должна быть доступна\n в папке установки. Если вам понравился МегаМек, пожалуйста, покажите другу.\n Если вы хотите его улучшить, учтите что ваши вклады\nТАКЖЕ должны распространяться через лицензию GNU версии 2 или выше.\n
CommonAboutDialog.copyright=МегаМек Copyright 2000-2005 Ben Mazur\n\nBattleTech, BattleMech, 'Mech, and MechWarrior являются зарегистрированным товарным знаком \r\nWizKids, LLC. Оригинальный материал BattleTech Copyright by WizKids, LLC.\nВсе права защищены. Используется без разрешения.
CommonAboutDialog.javaVendor=\nИзготовитель Java\u0020
CommonAboutDialog.javaVersion=\nВерсия Java\u0020
CommonAboutDialog.timestamp=\nВремя\u0020
CommonAboutDialog.title=О МегаМек
CommonAboutDialog.version=Версия МегаМек\u0020
CommonMenuBar.Active=Активно({0})
CommonMenuBar.AeroMenu=Аэрокосмос
CommonMenuBar.BoardMenu=Карта
Expand Down
1 change: 1 addition & 0 deletions megamek/src/megamek/MMConstants.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
*/
public final class MMConstants extends SuiteConstants {
//region General Constants
public static final String PROJECT_NAME = "MegaMek";
//endregion General Constants

//region GUI Constants
Expand Down
67 changes: 35 additions & 32 deletions megamek/src/megamek/MegaMek.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import megamek.client.ui.swing.ButtonOrderPreferences;
import megamek.client.ui.swing.MegaMekGUI;
import megamek.common.*;
import megamek.common.annotations.Nullable;
import megamek.common.preference.PreferenceManager;
import megamek.common.util.AbstractCommandLineParser;
import megamek.common.util.fileUtils.MegaMekFile;
Expand All @@ -35,7 +36,7 @@
import java.text.NumberFormat;
import java.time.LocalDate;
import java.util.Arrays;
import java.util.Date;
import java.util.Locale;
import java.util.Vector;

/**
Expand All @@ -46,9 +47,6 @@ public class MegaMek {
private static final SuitePreferences mmPreferences = new SuitePreferences();
private static final MMOptions mmOptions = new MMOptions();

public static long TIMESTAMP = new File(PreferenceManager.getClientPreferences().getLogDirectory()
+ File.separator + "timestamp").lastModified();

private static final NumberFormat commafy = NumberFormat.getInstance();
private static final String INCORRECT_ARGUMENTS_MESSAGE = "Incorrect arguments:";
private static final String ARGUMENTS_DESCRIPTION_MESSAGE = "Arguments syntax:\n\t MegaMek "
Expand All @@ -66,8 +64,7 @@ public static void main(String... args) {
});

// Second, let's handle logging
showInfo();
handleLegacyLogging();
initializeLogging(MMConstants.PROJECT_NAME);

// Third, Command Line Arguments and Startup
try {
Expand Down Expand Up @@ -97,6 +94,13 @@ public static void main(String... args) {
}
}

public static void initializeLogging(final String originProject) {
final String initialMessage = getUnderlyingInformation(originProject);
LogManager.getLogger().info(initialMessage);
handleLegacyLogging();
System.out.println(initialMessage);
}

/**
* This function redirects the standard error and output streams... It's a legacy method that
* is currently being used as a fallback while migrating the last of our legacy logging and
Expand Down Expand Up @@ -140,11 +144,10 @@ public static MMOptions getMMOptions() {

/**
* Calculates the SHA-256 hash of the MegaMek.jar file
* Used primarily for purposes of checksum comparison when
* connecting a new client.
* Used primarily for purposes of checksum comparison when connecting a new client.
* @return String representing the SHA-256 hash
*/
public static String getMegaMekSHA256() {
public static @Nullable String getMegaMekSHA256() {
StringBuilder sb = new StringBuilder();
byte[] buffer = new byte[8192];

Expand All @@ -168,7 +171,9 @@ public static String getMegaMekSHA256() {
}
try (InputStream is = new FileInputStream(filename);
InputStream dis = new DigestInputStream(is, md)) {
while (0 < dis.read(buffer)) { }
while (0 < dis.read(buffer)) {

}
// gets digest
byte[] digest = md.digest();
// convert the byte to hex format
Expand All @@ -183,8 +188,7 @@ public static String getMegaMekSHA256() {
}

/**
* This function returns the memory used in the heap (heap memory - free
* memory).
* This function returns the memory used in the heap (heap memory - free memory).
*
* @return memory used in kB
*/
Expand All @@ -196,8 +200,7 @@ public static String getMemoryUsed() {

/**
* Starts a dedicated server with the arguments in args. See
* {@link megamek.server.DedicatedServer#start(String[])} for more
* information.
* {@link DedicatedServer#start(String[])} for more information.
*
* @param args the arguments to the dedicated server.
*/
Expand All @@ -215,25 +218,25 @@ private static void startGUI() {
}

/**
* Prints some information about MegaMek. Used in log files to figure out the JVM and
* version of MegaMek.
* @param originProject the project that launched MegaMek
* @return the underlying information for this launch of MegaMek
*/
public static void showInfo() {
final long TIMESTAMP = new File(PreferenceManager.getClientPreferences().getLogDirectory()
+ File.separator + "timestamp").lastModified();
// echo some useful stuff
String msg = "Starting MegaMek v" + MMConstants.VERSION;
if (TIMESTAMP > 0) {
msg += "\n\tCompiled on " + new Date(TIMESTAMP);
}
msg += "\n\tToday is " + LocalDate.now()
+ "\n\tJava Vendor: " + System.getProperty("java.vendor")
+ "\n\tJava Version: " + System.getProperty("java.version")
+ "\n\tPlatform: " + System.getProperty("os.name") + " " + System.getProperty("os.version")
+ " (" + System.getProperty("os.arch") + ")"
+ "\n\tTotal memory available to MegaMek: "
+ NumberFormat.getInstance().format(Runtime.getRuntime().maxMemory()) + " GB";
LogManager.getLogger().info(msg);
public static String getUnderlyingInformation(final String originProject) {
return MegaMek.getUnderlyingInformation(originProject, MMConstants.PROJECT_NAME);
}

/**
* @param originProject the launching project
* @param currentProject the currently described project
* @return the underlying information for this launch
*/
public static String getUnderlyingInformation(final String originProject, final String currentProject) {
return String.format("Starting %s v%s\n\tRelease Date: %s\n\tToday: %s\n\tOrigin Project: %s\n\tJava Vendor: %s\n\tJava Version: %s\n\tPlatform: %s %s (%s)\n\tSystem Locale: %s\n\tTotal memory available to %s: %,.0f GB",
currentProject, MMConstants.VERSION, MMConstants.RELEASE_DATE, LocalDate.now(),
originProject, System.getProperty("java.vendor"), System.getProperty("java.version"),
System.getProperty("os.name"), System.getProperty("os.version"),
System.getProperty("os.arch"), Locale.getDefault(), currentProject,
Runtime.getRuntime().maxMemory() / Math.pow(2, 30));
}

/**
Expand Down
4 changes: 4 additions & 0 deletions megamek/src/megamek/SuiteConstants.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,16 @@
*/
package megamek;

import java.time.LocalDate;

/**
* These are constants that hold across the entire MegaMek Suite of MegaMek, MegaMekLab, and MekHQ.
*/
public abstract class SuiteConstants {
//region General Constants
public static final String PROJECT_NAME = "MegaMek Suite";
public static final Version VERSION = new Version("0.49.7-SNAPSHOT");
public static final LocalDate RELEASE_DATE = LocalDate.of(2021, 12, 31);
public static final int MAXIMUM_D6_VALUE = 6;

// This is used in creating the name of save files, e.g. the MekHQ campaign file
Expand Down
38 changes: 9 additions & 29 deletions megamek/src/megamek/client/ui/swing/CommonAboutDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,26 +15,15 @@
*/
package megamek.client.ui.swing;

import static megamek.MegaMek.TIMESTAMP;

import java.awt.BorderLayout;
import java.awt.Image;
import java.awt.MediaTracker;
import java.util.Date;

import javax.swing.BoxLayout;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextArea;

import megamek.MMConstants;
import megamek.MegaMek;
import megamek.client.ui.Messages;
import megamek.common.Configuration;
import megamek.common.util.fileUtils.MegaMekFile;
import org.apache.logging.log4j.LogManager;

import javax.swing.*;
import java.awt.*;

/**
* Every about dialog in MegaMek should have an identical look-and-feel.
Expand Down Expand Up @@ -65,10 +54,10 @@ private static synchronized Image getTitleImage(JFrame frame) {
try {
tracker.waitForID(0);
imgTitleImage = image;
} catch (InterruptedException exp) {
exp.printStackTrace();
} catch (Exception ex) {
LogManager.getLogger().error("", ex);
}
} // End load-imgTitleImage
}

return imgTitleImage;
}
Expand All @@ -86,16 +75,7 @@ public CommonAboutDialog(JFrame parentFrame) {
JLabel panTitle = new JLabel(new ImageIcon(imgSplash));

// Version text
StringBuffer buff = new StringBuffer();
buff.append(Messages.getString("CommonAboutDialog.version"))
.append(MMConstants.VERSION).append(
Messages.getString("CommonAboutDialog.timestamp"))
.append(new Date(TIMESTAMP)).append(
Messages.getString("CommonAboutDialog.javaVendor"))
.append(System.getProperty("java.vendor"))
.append(Messages.getString("CommonAboutDialog.javaVersion"))
.append(System.getProperty("java.version"));
JTextArea lblVersion = new JTextArea(buff.toString());
JTextArea lblVersion = new JTextArea(MegaMek.getUnderlyingInformation(MMConstants.PROJECT_NAME));
lblVersion.setEditable(false);
lblVersion.setOpaque(false);

Expand Down
8 changes: 2 additions & 6 deletions megamek/src/megamek/common/MechSummaryCache.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
*/
package megamek.common;

import megamek.MegaMek;
import megamek.common.loaders.EntityLoadingException;
import megamek.common.util.fileUtils.MegaMekFile;
import megamek.common.verifier.*;
Expand Down Expand Up @@ -74,7 +73,6 @@ public static synchronized MechSummaryCache getInstance(boolean ignoreUnofficial
}
if (!m_instance.initialized && !m_instance.initializing) {
m_instance.initializing = true;
m_instance.initialized = false;
interrupted = false;
disposeInstance = false;
m_instance.loader = new Thread(() -> m_instance.loadMechData(ignoringUnofficial),
Expand All @@ -97,8 +95,7 @@ public static void refreshUnitData(boolean ignoreUnofficial) {
interrupted = false;
disposeInstance = false;
File unit_cache_path = new MegaMekFile(getUnitCacheDir(), FILENAME_UNITS_CACHE).getFile();
long lastModified = unit_cache_path.exists() ?
unit_cache_path.lastModified() : megamek.MegaMek.TIMESTAMP;
long lastModified = unit_cache_path.exists() ? unit_cache_path.lastModified() : 0L;

m_instance.loader = new Thread(() -> m_instance.refreshCache(lastModified, ignoreUnofficial),
"Mech Cache Loader");
Expand Down Expand Up @@ -200,8 +197,7 @@ public void loadMechData(boolean ignoreUnofficial) {
FILENAME_UNITS_CACHE).getFile();
// check the cache
try {
if (unit_cache_path.exists()
&& (unit_cache_path.lastModified() >= MegaMek.TIMESTAMP)) {
if (unit_cache_path.exists()) {
loadReport.append(" Reading from unit cache file...\n");
lLastCheck = unit_cache_path.lastModified();
InputStream istream = new BufferedInputStream(
Expand Down
12 changes: 1 addition & 11 deletions megamek/src/megamek/server/Server.java
Original file line number Diff line number Diff line change
Expand Up @@ -502,17 +502,7 @@ public Game getGame() {
* it was found, the build timestamp
*/
private String createMotd() {
StringBuilder motd = new StringBuilder();
motd.append("Welcome to MegaMek. Server is running version ").append(MMConstants.VERSION)
.append(", build date ");
if (MegaMek.TIMESTAMP > 0L) {
motd.append(new Date(MegaMek.TIMESTAMP));
} else {
motd.append("unknown");
}
motd.append('.');

return motd.toString();
return "Welcome to MegaMek. Server is running version " + MMConstants.VERSION;
}

/**
Expand Down