Extend event logging functionality

This commit is contained in:
JeremyStar™ 2024-06-11 19:59:32 +02:00
parent c11fc78b86
commit 0031c4ef29
Signed by: JeremyStarTM
GPG key ID: E366BAEF67E4704D
2 changed files with 22 additions and 3 deletions

View file

@ -82,6 +82,14 @@ public final class EngineConfiguration implements SubsystemConfiguration {
*/ */
private boolean debug; private boolean debug;
/**
* If enabled, all called events will be logged.
*
* @see de.staropensource.sosengine.base.classes.helpers.EventHelper#logCall(Class)
* @since 1-alpha0
*/
private boolean debugEvents;
/** /**
* If enabled, very verbose messages about the {@link de.staropensource.sosengine.base.utility.ShortcodeConverter}'s internals will be printed.<br/> * If enabled, very verbose messages about the {@link de.staropensource.sosengine.base.utility.ShortcodeConverter}'s internals will be printed.<br/>
* Don't enable unless you have knowledge about the {@link de.staropensource.sosengine.base.utility.ShortcodeConverter} and want to work on it. * Don't enable unless you have knowledge about the {@link de.staropensource.sosengine.base.utility.ShortcodeConverter} and want to work on it.
@ -208,6 +216,7 @@ public final class EngineConfiguration implements SubsystemConfiguration {
try { try {
switch (property) { switch (property) {
case "debug" -> debug = parser.getBoolean(group + property); case "debug" -> debug = parser.getBoolean(group + property);
case "debugEvents" -> debugEvents = parser.getBoolean(group + property);
case "debugShortcodeConverter" -> debugShortcodeConverter = parser.getBoolean(group + property); case "debugShortcodeConverter" -> debugShortcodeConverter = parser.getBoolean(group + property);
case "errorShortcodeConverter" -> errorShortcodeConverter = parser.getBoolean(group + property); case "errorShortcodeConverter" -> errorShortcodeConverter = parser.getBoolean(group + property);
@ -228,6 +237,7 @@ public final class EngineConfiguration implements SubsystemConfiguration {
// Disable all debug options if 'debug' is disabled // Disable all debug options if 'debug' is disabled
if (!debug) { if (!debug) {
debugEvents = false;
debugShortcodeConverter = false; debugShortcodeConverter = false;
} }
} }
@ -240,6 +250,7 @@ public final class EngineConfiguration implements SubsystemConfiguration {
/** {@inheritDoc} */ /** {@inheritDoc} */
public void loadDefaultConfiguration() { public void loadDefaultConfiguration() {
debug = false; debug = false;
debugEvents = false;
debugShortcodeConverter = false; debugShortcodeConverter = false;
errorShortcodeConverter = true; errorShortcodeConverter = true;
@ -257,6 +268,9 @@ public final class EngineConfiguration implements SubsystemConfiguration {
case "debug" -> { case "debug" -> {
return debug; return debug;
} }
case "debugEvents" -> {
return debugEvents;
}
case "debugShortcodeConverter" -> { case "debugShortcodeConverter" -> {
return debugShortcodeConverter; return debugShortcodeConverter;
} }

View file

@ -19,10 +19,12 @@
package de.staropensource.sosengine.base.classes.helpers; package de.staropensource.sosengine.base.classes.helpers;
import de.staropensource.sosengine.base.EngineConfiguration;
import de.staropensource.sosengine.base.annotations.EventListener; import de.staropensource.sosengine.base.annotations.EventListener;
import de.staropensource.sosengine.base.classes.Event; import de.staropensource.sosengine.base.classes.Event;
import de.staropensource.sosengine.base.logging.Logger; import de.staropensource.sosengine.base.logging.Logger;
import de.staropensource.sosengine.base.types.LogIssuer; import de.staropensource.sosengine.base.types.LogIssuer;
import de.staropensource.sosengine.base.utility.ListFormatter;
import lombok.Getter; import lombok.Getter;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.reflections.Reflections; import org.reflections.Reflections;
@ -53,9 +55,12 @@ public class EventHelper {
* @param clazz event class * @param clazz event class
* @since 1-alpha0 * @since 1-alpha0
*/ */
@NotNull public static void logCall(Class<? extends Event> clazz, Object ... arguments) {
public static void logCall(Class<? extends Event> clazz) { if (EngineConfiguration.getInstance().isDebugEvents())
Logger.diag(new LogIssuer(clazz), "Event " + clazz.getName() + " called"); if (arguments.length == 0)
Logger.diag(new LogIssuer(clazz), "Event " + clazz.getName() + " called");
else
Logger.diag(new LogIssuer(clazz), "Event " + clazz.getName() + " called with arguments " + ListFormatter.formatArray(arguments));
} }
/** /**