From 947765b5d8cdac87c90c937143c5031da17fea64 Mon Sep 17 00:00:00 2001 From: Bram Date: Sat, 27 Apr 2024 21:43:57 +0200 Subject: [PATCH] Added: Debug message support in the LogManager Refactored: File structure for the "wrappers" --- .../{wrappers => }/interfaces/Scheduler.java | 2 +- .../managers/LogManager.java | 82 +++++++++++++++++++ .../wrappers/LogManager.java | 38 --------- 3 files changed, 83 insertions(+), 39 deletions(-) rename common/src/main/java/com/deathmotion/antihealthindicator/{wrappers => }/interfaces/Scheduler.java (94%) create mode 100644 common/src/main/java/com/deathmotion/antihealthindicator/managers/LogManager.java delete mode 100644 common/src/main/java/com/deathmotion/antihealthindicator/wrappers/LogManager.java diff --git a/common/src/main/java/com/deathmotion/antihealthindicator/wrappers/interfaces/Scheduler.java b/common/src/main/java/com/deathmotion/antihealthindicator/interfaces/Scheduler.java similarity index 94% rename from common/src/main/java/com/deathmotion/antihealthindicator/wrappers/interfaces/Scheduler.java rename to common/src/main/java/com/deathmotion/antihealthindicator/interfaces/Scheduler.java index 964fb17..71ffdd9 100644 --- a/common/src/main/java/com/deathmotion/antihealthindicator/wrappers/interfaces/Scheduler.java +++ b/common/src/main/java/com/deathmotion/antihealthindicator/interfaces/Scheduler.java @@ -16,7 +16,7 @@ * along with this program. If not, see . */ -package com.deathmotion.antihealthindicator.wrappers.interfaces; +package com.deathmotion.antihealthindicator.interfaces; import org.jetbrains.annotations.NotNull; diff --git a/common/src/main/java/com/deathmotion/antihealthindicator/managers/LogManager.java b/common/src/main/java/com/deathmotion/antihealthindicator/managers/LogManager.java new file mode 100644 index 0000000..86845e5 --- /dev/null +++ b/common/src/main/java/com/deathmotion/antihealthindicator/managers/LogManager.java @@ -0,0 +1,82 @@ +/* + * This file is part of AntiHealthIndicator - https://github.com/Bram1903/AntiHealthIndicator + * Copyright (C) 2024 Bram and contributors + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.deathmotion.antihealthindicator.managers; + +import com.deathmotion.antihealthindicator.AHIPlatform; +import com.deathmotion.antihealthindicator.enums.ConfigOption; + +import java.util.logging.Logger; + +/** + * LogManager class to handle all kinds of logging messages. + * This class supports logging info, warning, error and debug messages. + * + * @param

the platform type. + */ +public final class LogManager

{ + private final Logger logger = Logger.getLogger("AntiHealthIndicator"); + private final boolean debugEnabled; + + /** + * A constructor to initialize LogManager. + * + * @param platform AHIPlatform instance with platform-specific configurations. + */ + public LogManager(AHIPlatform

platform) { + this.debugEnabled = platform.getConfigurationOption(ConfigOption.DEBUG_ENABLED); + } + + /** + * Logs the information messages + * + * @param message the message to be logged as info + */ + public void info(String message) { + logger.info(message); + } + + /** + * Logs the warning messages + * + * @param message the message to be logged as warning + */ + public void warning(String message) { + logger.warning(message); + } + + /** + * Logs the error messages + * + * @param message the message to be logged as error + */ + public void error(String message) { + logger.severe(message); + } + + /** + * Logs the debug messages, but only if debug mode is enabled. + * + * @param message the message to be logged as debug + */ + public void debug(String message) { + if (debugEnabled) { + logger.info("[DEBUG] " + message); + } + } +} \ No newline at end of file diff --git a/common/src/main/java/com/deathmotion/antihealthindicator/wrappers/LogManager.java b/common/src/main/java/com/deathmotion/antihealthindicator/wrappers/LogManager.java deleted file mode 100644 index 2b35ea2..0000000 --- a/common/src/main/java/com/deathmotion/antihealthindicator/wrappers/LogManager.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * This file is part of AntiHealthIndicator - https://github.com/Bram1903/AntiHealthIndicator - * Copyright (C) 2024 Bram and contributors - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package com.deathmotion.antihealthindicator.wrappers; - -import java.util.logging.Logger; - -public final class LogManager { - - private final Logger logger = Logger.getLogger("AntiHealthIndicator"); - - public void info(String message) { - logger.info(message); - } - - public void warning(String message) { - logger.warning(message); - } - - public void error(String message) { - logger.severe(message); - } -} \ No newline at end of file