From cf8e27f039fd3273504fadb934378f409f45a901 Mon Sep 17 00:00:00 2001 From: Liam Date: Fri, 19 Apr 2024 23:24:51 +0100 Subject: [PATCH] add topics for logging --- src/main/java/xyz/mcutils/backend/Main.java | 2 +- .../java/xyz/mcutils/backend/common/ImageUtils.java | 2 +- .../xyz/mcutils/backend/common/PlayerUtils.java | 2 +- .../backend/common/renderer/SkinRenderer.java | 2 +- .../backend/common/renderer/impl/BodyRenderer.java | 2 +- .../common/renderer/impl/SquareRenderer.java | 2 +- .../java/xyz/mcutils/backend/config/Config.java | 2 +- .../java/xyz/mcutils/backend/model/skin/Skin.java | 2 +- .../xyz/mcutils/backend/service/MetricService.java | 2 +- .../xyz/mcutils/backend/service/MojangService.java | 2 +- .../xyz/mcutils/backend/service/PlayerService.java | 2 +- .../xyz/mcutils/backend/service/ServerService.java | 2 +- .../pinger/impl/BedrockMinecraftServerPinger.java | 13 ++++++------- .../pinger/impl/JavaMinecraftServerPinger.java | 7 ++++--- 14 files changed, 22 insertions(+), 22 deletions(-) diff --git a/src/main/java/xyz/mcutils/backend/Main.java b/src/main/java/xyz/mcutils/backend/Main.java index bf5102c..2e98d64 100644 --- a/src/main/java/xyz/mcutils/backend/Main.java +++ b/src/main/java/xyz/mcutils/backend/Main.java @@ -13,7 +13,7 @@ import java.nio.file.Files; import java.nio.file.StandardCopyOption; import java.util.Objects; -@Log4j2 +@Log4j2(topic = "Main") @SpringBootApplication public class Main { public static final Gson GSON = new GsonBuilder() diff --git a/src/main/java/xyz/mcutils/backend/common/ImageUtils.java b/src/main/java/xyz/mcutils/backend/common/ImageUtils.java index 9b57513..fd9dc90 100644 --- a/src/main/java/xyz/mcutils/backend/common/ImageUtils.java +++ b/src/main/java/xyz/mcutils/backend/common/ImageUtils.java @@ -10,7 +10,7 @@ import java.awt.geom.AffineTransform; import java.awt.image.BufferedImage; import java.io.ByteArrayOutputStream; -@Log4j2 +@Log4j2(topic = "Image Utils") public class ImageUtils { /** * Scale the given image to the provided size. diff --git a/src/main/java/xyz/mcutils/backend/common/PlayerUtils.java b/src/main/java/xyz/mcutils/backend/common/PlayerUtils.java index 0384157..94ee28c 100644 --- a/src/main/java/xyz/mcutils/backend/common/PlayerUtils.java +++ b/src/main/java/xyz/mcutils/backend/common/PlayerUtils.java @@ -12,7 +12,7 @@ import java.net.http.HttpRequest; import java.net.http.HttpResponse; import java.util.UUID; -@UtilityClass @Log4j2 +@UtilityClass @Log4j2(topic = "Player Utils") public class PlayerUtils { /** diff --git a/src/main/java/xyz/mcutils/backend/common/renderer/SkinRenderer.java b/src/main/java/xyz/mcutils/backend/common/renderer/SkinRenderer.java index 180c2dd..4292538 100644 --- a/src/main/java/xyz/mcutils/backend/common/renderer/SkinRenderer.java +++ b/src/main/java/xyz/mcutils/backend/common/renderer/SkinRenderer.java @@ -11,7 +11,7 @@ import java.awt.*; import java.awt.image.BufferedImage; import java.io.ByteArrayInputStream; -@Log4j2 +@Log4j2(topic = "Skin Renderer") public abstract class SkinRenderer { /** diff --git a/src/main/java/xyz/mcutils/backend/common/renderer/impl/BodyRenderer.java b/src/main/java/xyz/mcutils/backend/common/renderer/impl/BodyRenderer.java index a8d7a63..50f6d35 100644 --- a/src/main/java/xyz/mcutils/backend/common/renderer/impl/BodyRenderer.java +++ b/src/main/java/xyz/mcutils/backend/common/renderer/impl/BodyRenderer.java @@ -11,7 +11,7 @@ import xyz.mcutils.backend.model.skin.Skin; import java.awt.*; import java.awt.image.BufferedImage; -@AllArgsConstructor @Getter @Log4j2 +@AllArgsConstructor @Getter @Log4j2(topic = "Skin Renderer/Body") public class BodyRenderer extends SkinRenderer { public static final BodyRenderer INSTANCE = new BodyRenderer(); diff --git a/src/main/java/xyz/mcutils/backend/common/renderer/impl/SquareRenderer.java b/src/main/java/xyz/mcutils/backend/common/renderer/impl/SquareRenderer.java index d40acf0..214111e 100644 --- a/src/main/java/xyz/mcutils/backend/common/renderer/impl/SquareRenderer.java +++ b/src/main/java/xyz/mcutils/backend/common/renderer/impl/SquareRenderer.java @@ -10,7 +10,7 @@ import xyz.mcutils.backend.model.skin.Skin; import java.awt.*; import java.awt.image.BufferedImage; -@AllArgsConstructor @Getter @Log4j2 +@AllArgsConstructor @Getter @Log4j2(topic = "Skin Renderer/Square") public class SquareRenderer extends SkinRenderer { public static final SquareRenderer INSTANCE = new SquareRenderer(); diff --git a/src/main/java/xyz/mcutils/backend/config/Config.java b/src/main/java/xyz/mcutils/backend/config/Config.java index 5860983..4f73a02 100644 --- a/src/main/java/xyz/mcutils/backend/config/Config.java +++ b/src/main/java/xyz/mcutils/backend/config/Config.java @@ -14,7 +14,7 @@ import org.springframework.web.filter.ShallowEtagHeaderFilter; import org.springframework.web.servlet.config.annotation.CorsRegistry; import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; -@Getter @Log4j2 +@Getter @Log4j2(topic = "Config") @Configuration public class Config { public static Config INSTANCE; diff --git a/src/main/java/xyz/mcutils/backend/model/skin/Skin.java b/src/main/java/xyz/mcutils/backend/model/skin/Skin.java index 70a50fe..0d29e0d 100644 --- a/src/main/java/xyz/mcutils/backend/model/skin/Skin.java +++ b/src/main/java/xyz/mcutils/backend/model/skin/Skin.java @@ -19,7 +19,7 @@ import java.util.HashMap; import java.util.Map; @AllArgsConstructor @NoArgsConstructor -@Getter @Log4j2 @EqualsAndHashCode +@Getter @Log4j2(topic = "Skin") @EqualsAndHashCode public class Skin { /** * The URL for the skin diff --git a/src/main/java/xyz/mcutils/backend/service/MetricService.java b/src/main/java/xyz/mcutils/backend/service/MetricService.java index d7cc37f..4260dac 100644 --- a/src/main/java/xyz/mcutils/backend/service/MetricService.java +++ b/src/main/java/xyz/mcutils/backend/service/MetricService.java @@ -20,7 +20,7 @@ import java.util.List; import java.util.Map; import java.util.concurrent.TimeUnit; -@Service @Log4j2 +@Service @Log4j2(topic = "Metric Service") public class MetricService { /** * The metrics that are registered. diff --git a/src/main/java/xyz/mcutils/backend/service/MojangService.java b/src/main/java/xyz/mcutils/backend/service/MojangService.java index e4b690c..d651f65 100644 --- a/src/main/java/xyz/mcutils/backend/service/MojangService.java +++ b/src/main/java/xyz/mcutils/backend/service/MojangService.java @@ -28,7 +28,7 @@ import java.nio.charset.StandardCharsets; import java.util.*; import java.util.concurrent.TimeUnit; -@Service @Log4j2 @Getter +@Service @Log4j2(topic = "Mojang Service") @Getter public class MojangService { /** diff --git a/src/main/java/xyz/mcutils/backend/service/PlayerService.java b/src/main/java/xyz/mcutils/backend/service/PlayerService.java index 539e485..649cf38 100644 --- a/src/main/java/xyz/mcutils/backend/service/PlayerService.java +++ b/src/main/java/xyz/mcutils/backend/service/PlayerService.java @@ -26,7 +26,7 @@ import java.awt.image.BufferedImage; import java.util.Optional; import java.util.UUID; -@Service @Log4j2 +@Service @Log4j2(topic = "Player Service") public class PlayerService { private final MojangService mojangAPIService; diff --git a/src/main/java/xyz/mcutils/backend/service/ServerService.java b/src/main/java/xyz/mcutils/backend/service/ServerService.java index 9aaeecf..270938b 100644 --- a/src/main/java/xyz/mcutils/backend/service/ServerService.java +++ b/src/main/java/xyz/mcutils/backend/service/ServerService.java @@ -23,7 +23,7 @@ import java.util.Base64; import java.util.List; import java.util.Optional; -@Service @Log4j2 +@Service @Log4j2(topic = "Server Service") public class ServerService { private static final String DEFAULT_SERVER_ICON = "iVBORw0KGgoAAAANSUhEUgAAAEAAAABACAMAAACdt4HsAAAASFBMVEWwsLBBQUE9PT1JSUlFRUUuLi5MTEyzs7M0NDQ5OTlVVVVQUFAmJia5ubl+fn5zc3PFxcVdXV3AwMCJiYmUlJRmZmbQ0NCjo6OL5p+6AAAFVklEQVRYw+1W67K0KAzkJnIZdRAZ3/9NtzvgXM45dX7st1VbW7XBUVDSdEISRqn/5R+T82/+nsr/XZn/SHm/3x9/ArA/IP8qwPK433d44VubZ/XT6/cJy0L792VZfnDrcRznr86d748u92X5vtaxOe228zcCy+MSMpg/5SwRopsYMv8oigCwngbQhE/rzhwAYMpxnvMvHhgy/8AgByJolzb5pPqEbvtgMBBmtvkbgx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Wu0y9gMHsEapMMEoySNUA2RDrduxIqr5POQV2zZ++IBOwVrFO9THrtjU2uWsCMZjxXl88Hmeaz1rPdAqXyJl68F5RTtdvN1aIyYEAMAWJaCMHvon7s23jljlxoKBEgNv6LQ25/rZIQyOdwDO3jLsqE2nbVAil21LxqFpZ2xJ3CFuE33QCo7kfkfO8kpW6gdioxdzZDLOaMMwidzeKD0RxaD7cnHHsu0jVkW5oTwwMGI0lwwA36u2nMY8AKzErLW9JxFiteyzZsAAxY1vPe5Uf68lIDVjV8JZpPfjxbc/QuyRKdAQJaAdIA4tCTht+kQJ1I4nbdjfHxgpTSLyI19pb/iuK7+9YJaZCxEIKj79YZ6uDU8f97878teRN1FzA7OvquSrVKUgk+S6ROpJfA7GpN6RPkx4voshXgu91p7CGHeA+IY8dUUVXwT7PYw12Xsj0Lfh9X4ac9XgKW86cj8bPh8XmyDOD88FLoB+YPXp4YtyB3gBPXu98xeRI2zploVCBQAAAABJRU5ErkJggg=="; diff --git a/src/main/java/xyz/mcutils/backend/service/pinger/impl/BedrockMinecraftServerPinger.java b/src/main/java/xyz/mcutils/backend/service/pinger/impl/BedrockMinecraftServerPinger.java index 7afbe0d..38641fe 100644 --- a/src/main/java/xyz/mcutils/backend/service/pinger/impl/BedrockMinecraftServerPinger.java +++ b/src/main/java/xyz/mcutils/backend/service/pinger/impl/BedrockMinecraftServerPinger.java @@ -50,19 +50,18 @@ public final class BedrockMinecraftServerPinger implements MinecraftServerPinger unconnectedPong.process(socket); String response = unconnectedPong.getResponse(); if (response == null) { // No pong response - throw new ResourceNotFoundException("Server didn't respond to ping"); + throw new ResourceNotFoundException("Server '%s' didn't respond to ping".formatted(hostname)); } return BedrockMinecraftServer.create(hostname, ip, port, records, response); // Return the server } catch (IOException ex ) { if (ex instanceof UnknownHostException) { - throw new BadRequestException("Unknown hostname: %s".formatted(hostname)); + throw new BadRequestException("Unknown hostname '%s'".formatted(hostname)); } else if (ex instanceof SocketTimeoutException) { - throw new ResourceNotFoundException(ex); - } else if (ex instanceof SocketException) { - throw new BadRequestException("An error occurred pinging %s:%s".formatted(hostname, port)); + throw new ResourceNotFoundException("Server '%s' didn't respond to ping".formatted(hostname)); + } else { + log.error("An error occurred pinging %s:%s:".formatted(hostname, port), ex); + throw new BadRequestException("An error occurred pinging '%s:%s'".formatted(hostname, port)); } - log.error("An error occurred pinging %s:%s:".formatted(hostname, port), ex); } - return null; } } \ No newline at end of file diff --git a/src/main/java/xyz/mcutils/backend/service/pinger/impl/JavaMinecraftServerPinger.java b/src/main/java/xyz/mcutils/backend/service/pinger/impl/JavaMinecraftServerPinger.java index 987130a..f456e13 100644 --- a/src/main/java/xyz/mcutils/backend/service/pinger/impl/JavaMinecraftServerPinger.java +++ b/src/main/java/xyz/mcutils/backend/service/pinger/impl/JavaMinecraftServerPinger.java @@ -50,10 +50,11 @@ public final class JavaMinecraftServerPinger implements MinecraftServerPinger