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;
/**
* 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/>
* 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 {
switch (property) {
case "debug" -> debug = parser.getBoolean(group + property);
case "debugEvents" -> debugEvents = parser.getBoolean(group + property);
case "debugShortcodeConverter" -> debugShortcodeConverter = 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
if (!debug) {
debugEvents = false;
debugShortcodeConverter = false;
}
}
@ -240,6 +250,7 @@ public final class EngineConfiguration implements SubsystemConfiguration {
/** {@inheritDoc} */
public void loadDefaultConfiguration() {
debug = false;
debugEvents = false;
debugShortcodeConverter = false;
errorShortcodeConverter = true;
@ -257,6 +268,9 @@ public final class EngineConfiguration implements SubsystemConfiguration {
case "debug" -> {
return debug;
}
case "debugEvents" -> {
return debugEvents;
}
case "debugShortcodeConverter" -> {
return debugShortcodeConverter;
}

View file

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