Skip to content

Commit e81e74c

Browse files
committed
Use parameterized messages for logging
1 parent ea7695d commit e81e74c

10 files changed

Lines changed: 27 additions & 27 deletions

File tree

src/main/java/net/raphimc/viaproxy/ViaProxy.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -170,20 +170,20 @@ public static void injectedMain(final String injectionMethod, final String[] arg
170170
Logger.setup();
171171
if (!useUI && !useConfig && !useCLI) {
172172
final String fileName = JarUtil.getJarFile().map(File::getName).orElse("ViaProxy.jar");
173-
Logger.LOGGER.info("Usage: java -jar " + fileName + " | Starts ViaProxy in graphical mode if available");
174-
Logger.LOGGER.info("Usage: java -jar " + fileName + " config <config file> | Starts ViaProxy with the specified config file");
175-
Logger.LOGGER.info("Usage: java -jar " + fileName + " cli --help | Starts ViaProxy in CLI mode");
173+
Logger.LOGGER.info("Usage: java -jar {} | Starts ViaProxy in graphical mode if available", fileName);
174+
Logger.LOGGER.info("Usage: java -jar {} config <config file> | Starts ViaProxy with the specified config file", fileName);
175+
Logger.LOGGER.info("Usage: java -jar {} cli --help | Starts ViaProxy in CLI mode", fileName);
176176
System.exit(1);
177177
}
178178

179179
Logger.LOGGER.info("Initializing ViaProxy {} v{} ({}) (Injected using {})...", useUI ? "GUI" : "CLI", VERSION, IMPL_VERSION, injectionMethod);
180-
Logger.LOGGER.info("Using java version: " + System.getProperty("java.vm.name") + " " + System.getProperty("java.version") + " (" + System.getProperty("java.vendor") + ") on " + System.getProperty("os.name"));
181-
Logger.LOGGER.info("Available memory (bytes): " + Runtime.getRuntime().maxMemory());
182-
Logger.LOGGER.info("Working directory: " + CWD.getAbsolutePath());
180+
Logger.LOGGER.info("Using java version: {} {} ({}) on {}", System.getProperty("java.vm.name"), System.getProperty("java.version"), System.getProperty("java.vendor"), System.getProperty("os.name"));
181+
Logger.LOGGER.info("Available memory (bytes): {}", Runtime.getRuntime().maxMemory());
182+
Logger.LOGGER.info("Working directory: {}", CWD.getAbsolutePath());
183183
if (!failedCwds.isEmpty()) {
184184
Logger.LOGGER.warn("Failed to use the following directories as working directory:");
185185
for (File failedCwd : failedCwds) {
186-
Logger.LOGGER.warn("\t- " + failedCwd.getAbsolutePath());
186+
Logger.LOGGER.warn("\t- {}", failedCwd.getAbsolutePath());
187187
}
188188
}
189189
if (System.getProperty("ignoreSystemRequirements") == null) {
@@ -266,7 +266,7 @@ public static void injectedMain(final String injectionMethod, final String[] arg
266266
throw new RuntimeException("Failed to load CLI arguments", e);
267267
}
268268
} else if (firstStart) {
269-
Logger.LOGGER.info("This is the first start of ViaProxy. Please configure the settings in the " + viaProxyConfigFile.getName() + " file and restart ViaProxy.");
269+
Logger.LOGGER.info("This is the first start of ViaProxy. Please configure the settings in the {} file and restart ViaProxy.", viaProxyConfigFile.getName());
270270
System.exit(0);
271271
}
272272

@@ -289,7 +289,7 @@ public static void startProxy() {
289289
Logger.LOGGER.info("Starting proxy server");
290290
currentProxyServer = new NetServer(new Client2ProxyChannelInitializer(() -> EVENT_MANAGER.call(new Client2ProxyHandlerCreationEvent(new Client2ProxyHandler(), false)).getHandler()));
291291
EVENT_MANAGER.call(new ProxyStartEvent());
292-
Logger.LOGGER.info("Binding proxy server to " + AddressUtil.toString(CONFIG.getFrontend().getBindAddress()));
292+
Logger.LOGGER.info("Binding proxy server to {}", AddressUtil.toString(CONFIG.getFrontend().getBindAddress()));
293293
currentProxyServer.bind(CONFIG.getFrontend().getBindAddress(), false);
294294
} catch (Throwable e) {
295295
currentProxyServer = null;

src/main/java/net/raphimc/viaproxy/cli/command/CommandManager.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public CommandManager() {
7070
}
7171
this.commands.add(command);
7272
} catch (Throwable e) {
73-
Logger.LOGGER.error("Failed to register command " + command.getNames()[0], e);
73+
Logger.LOGGER.error("Failed to register command {}", command.getNames()[0], e);
7474
}
7575
});
7676

src/main/java/net/raphimc/viaproxy/plugins/PluginManager.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ private void loadPlugins() {
8282
try {
8383
loadAndScanJar(file);
8484
} catch (Throwable e) {
85-
Logger.LOGGER.error("Unable to load plugin '" + file.getName() + "'", e);
85+
Logger.LOGGER.error("Unable to load plugin '{}'", file.getName(), e);
8686
}
8787
}
8888

@@ -138,15 +138,15 @@ private void loadAndScanJar(final File file) throws Throwable {
138138
throw new IllegalStateException("Plugin '" + file.getName() + "' has more than one dependency. This is not supported yet.");
139139
}
140140

141-
Logger.LOGGER.info("Loaded plugin '" + plugin.getName() + "' by " + plugin.getAuthor() + " (v" + plugin.getVersion() + ")");
141+
Logger.LOGGER.info("Loaded plugin '{}' by {} (v{})", plugin.getName(), plugin.getAuthor(), plugin.getVersion());
142142
this.plugins.add(plugin);
143143
}
144144

145145
private void enablePlugin(final ViaProxyPlugin plugin) {
146146
for (String depend : plugin.getDepends()) {
147147
final ViaProxyPlugin dependPlugin = this.getPlugin(depend);
148148
if (dependPlugin == null) {
149-
Logger.LOGGER.error("Plugin '" + plugin.getName() + "' depends on '" + depend + "' which is not loaded");
149+
Logger.LOGGER.error("Plugin '{}' depends on '{}' which is not loaded", plugin.getName(), depend);
150150
return;
151151
}
152152
if (!dependPlugin.isEnabled()) {
@@ -158,9 +158,9 @@ private void enablePlugin(final ViaProxyPlugin plugin) {
158158

159159
try {
160160
plugin.enable();
161-
Logger.LOGGER.info("Enabled plugin '" + plugin.getName() + "'");
161+
Logger.LOGGER.info("Enabled plugin '{}'", plugin.getName());
162162
} catch (Throwable e) {
163-
Logger.LOGGER.error("Failed to enable plugin '" + plugin.getName() + "'", e);
163+
Logger.LOGGER.error("Failed to enable plugin '{}'", plugin.getName(), e);
164164
}
165165
}
166166

@@ -176,7 +176,7 @@ private void disablePlugin(final ViaProxyPlugin plugin) {
176176
for (String depend : plugin.getDepends()) {
177177
final ViaProxyPlugin dependPlugin = this.getPlugin(depend);
178178
if (dependPlugin == null) {
179-
Logger.LOGGER.error("Plugin '" + plugin.getName() + "' depends on '" + depend + "' which is not loaded");
179+
Logger.LOGGER.error("Plugin '{}' depends on '{}' which is not loaded", plugin.getName(), depend);
180180
return;
181181
}
182182
if (dependPlugin.isEnabled()) {
@@ -186,9 +186,9 @@ private void disablePlugin(final ViaProxyPlugin plugin) {
186186

187187
try {
188188
plugin.disable();
189-
Logger.LOGGER.info("Disabled plugin '" + plugin.getName() + "'");
189+
Logger.LOGGER.info("Disabled plugin '{}'", plugin.getName());
190190
} catch (Throwable e) {
191-
Logger.LOGGER.error("Failed to disable plugin '" + plugin.getName() + "'", e);
191+
Logger.LOGGER.error("Failed to disable plugin '{}'", plugin.getName(), e);
192192
}
193193
}
194194

src/main/java/net/raphimc/viaproxy/proxy/packethandler/LoginPacketHandler.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ public boolean handleC2P(Packet packet, List<ChannelFutureListener> listeners) t
132132
Logger.u_info("auth", this.proxyConnection, "Authenticated as " + this.proxyConnection.getGameProfile().id().toString());
133133
} catch (CloseAndReturn ignored) {
134134
} catch (Throwable e) {
135-
Logger.LOGGER.error("Failed to make session request for user '" + profileName + "'!", e);
135+
Logger.LOGGER.error("Failed to make session request for user '{}'!", profileName, e);
136136
try {
137137
this.proxyConnection.kickClient("§cFailed to authenticate with Mojang servers! Please try again later.");
138138
} catch (Throwable ignored) {

src/main/java/net/raphimc/viaproxy/proxy/packethandler/StatusPacketHandler.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public boolean handleP2S(Packet packet, List<ChannelFutureListener> listeners) {
5656
final byte[] faviconBytes = Files.readAllBytes(new File(ViaProxy.getCwd(), ViaProxy.getConfig().getFrontend().getMotd().getFaviconPath()).toPath());
5757
FAVICON_BASE_64 = "data:image/png;base64," + Base64.getEncoder().encodeToString(faviconBytes);
5858
} catch (Throwable e) {
59-
Logger.LOGGER.error("Failed to load custom favicon from path: " + ViaProxy.getConfig().getFrontend().getMotd().getFaviconPath(), e);
59+
Logger.LOGGER.error("Failed to load custom favicon from path: {}", ViaProxy.getConfig().getFrontend().getMotd().getFaviconPath(), e);
6060
FAVICON_BASE_64 = "";
6161
}
6262
}

src/main/java/net/raphimc/viaproxy/saves/SaveManager.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public SaveManager() {
6666
save.load(saveObject.remove(save.getName()));
6767
}
6868
} catch (Throwable e) {
69-
Logger.LOGGER.error("Failed to load save " + save.getName(), e);
69+
Logger.LOGGER.error("Failed to load save {}", save.getName(), e);
7070
}
7171
});
7272

@@ -96,7 +96,7 @@ public synchronized void save() {
9696
saveObject.add(save.getName(), saveData);
9797
}
9898
} catch (Throwable e) {
99-
Logger.LOGGER.error("Failed to save save " + save.getName(), e);
99+
Logger.LOGGER.error("Failed to save save {}", save.getName(), e);
100100
}
101101
});
102102

src/main/java/net/raphimc/viaproxy/tasks/UpdateCheckTask.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ public void run() {
7676
updateAvailable = !VERSION.equals(latestVersion);
7777
}
7878
if (updateAvailable) {
79-
Logger.LOGGER.warn("You are running an outdated version of ViaProxy! Latest version: " + latestVersion);
79+
Logger.LOGGER.warn("You are running an outdated version of ViaProxy! Latest version: {}", latestVersion);
8080
if (this.hasUI && JarUtil.getJarFile().isPresent()) {
8181
final boolean runsJava8 = System.getProperty("java.version").startsWith("1.8");
8282
JsonArray assets = object.getAsJsonArray("assets");

src/main/java/net/raphimc/viaproxy/ui/ViaProxyWindow.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ public static void openURL(final String url) {
135135
}
136136

137137
public static void showException(final Throwable t) {
138-
Logger.LOGGER.error("Caught exception in thread " + Thread.currentThread().getName(), t);
138+
Logger.LOGGER.error("Caught exception in thread {}", Thread.currentThread().getName(), t);
139139
StringBuilder builder = new StringBuilder("An error occurred:\n");
140140
builder.append("[").append(t.getClass().getSimpleName()).append("] ").append(t.getMessage()).append("\n");
141141
for (StackTraceElement element : t.getStackTrace()) builder.append(element.toString()).append("\n");

src/main/java/net/raphimc/viaproxy/util/ClassLoaderPriorityUtil.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,10 @@ public static void loadOverridingJars() {
3737
try {
3838
if (file.getName().endsWith(".jar")) {
3939
ClassLoaders.loadToFront(file.toURI().toURL());
40-
Logger.LOGGER.warn("Loaded overriding jar " + file.getName());
40+
Logger.LOGGER.warn("Loaded overriding jar {}", file.getName());
4141
}
4242
} catch (Throwable e) {
43-
Logger.LOGGER.error("Failed to load overriding jar " + file.getName(), e);
43+
Logger.LOGGER.error("Failed to load overriding jar {}", file.getName(), e);
4444
}
4545
}
4646
}

src/main/java/net/raphimc/viaproxy/util/logging/Logger.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public static void u_log(final Level level, final String title, final ProxyConne
6565
}
6666

6767
public static void u_log(final Level level, final String title, final SocketAddress address, final GameProfile gameProfile, final String msg) {
68-
LOGGER.log(level, "[" + title.toUpperCase(Locale.ROOT) + "] (" + AddressUtil.toString(address) + " | " + (gameProfile != null ? gameProfile.name() : "null") + ") " + msg);
68+
LOGGER.log(level, "[{}] ({} | {}) {}", title.toUpperCase(Locale.ROOT), AddressUtil.toString(address), gameProfile != null ? gameProfile.name() : "null", msg);
6969
}
7070

7171
}

0 commit comments

Comments
 (0)