From ed1c1d3b1a2c2878e7b070044310483a66feed17 Mon Sep 17 00:00:00 2001 From: JeremyStarTM Date: Mon, 2 Dec 2024 20:59:47 +0100 Subject: [PATCH] Add 'level' and 'origin' log features --- .../engine/base/EngineConfiguration.java | 4 +- .../base/logging/backend/Processor.java | 51 ++++++++++--------- 2 files changed, 31 insertions(+), 24 deletions(-) diff --git a/base/src/main/java/de/staropensource/engine/base/EngineConfiguration.java b/base/src/main/java/de/staropensource/engine/base/EngineConfiguration.java index afd1ca647..f367258c8 100644 --- a/base/src/main/java/de/staropensource/engine/base/EngineConfiguration.java +++ b/base/src/main/java/de/staropensource/engine/base/EngineConfiguration.java @@ -309,6 +309,8 @@ public final class EngineConfiguration extends Configuration { *
  • moduleVersion (requires moduleName)
  • *
  • methodName
  • *
  • lineNumber
  • + *
  • level
  • + *
  • origin
  • * * * @return optional features to enable @@ -490,7 +492,7 @@ public final class EngineConfiguration extends Configuration { optimizeEvents = true; logLevel = LogLevel.INFORMATIONAL; - logFeatures = Set.of("formatting", "time", "methodName", "lineNumber"); + logFeatures = Set.of("formatting", "time", "methodName", "lineNumber", "level", "origin"); logPollingSpeed = 5; logForceStandardOutput = false; diff --git a/base/src/main/java/de/staropensource/engine/base/logging/backend/Processor.java b/base/src/main/java/de/staropensource/engine/base/logging/backend/Processor.java index fc74e0d21..6dd540b6b 100644 --- a/base/src/main/java/de/staropensource/engine/base/logging/backend/Processor.java +++ b/base/src/main/java/de/staropensource/engine/base/logging/backend/Processor.java @@ -113,20 +113,25 @@ public final class Processor { if (isFeatureEnabled("date") || isFeatureEnabled("time")) { output.append("["); date(output); - if (isFeatureEnabled("date")) + if (isFeatureEnabled("date") && isFeatureEnabled("time")) output.append(" "); time(output); output.append("] "); } - output.append("["); - level(output, level); - format(output, level); - output.append(" "); - issuerClass(output, level, issuer); - issuerModule(output, level, issuer); - methodName(output, level, issuer); - lineNumber(output, level, issuer); - output.append("] "); + + if (isFeatureEnabled("level") || isFeatureEnabled("origin")) { + output.append("["); + level(output, level); + if (isFeatureEnabled("level") && isFeatureEnabled("origin")) + output.append(" "); + if (isFeatureEnabled("origin")) { + issuerClass(output, level, issuer); + issuerModule(output, level, issuer); + methodName(output, level, issuer); + lineNumber(output, level, issuer); + } + output.append("] "); + } message(output, message); format(output, "reset"); @@ -244,19 +249,21 @@ public final class Processor { * @since v1-alpha8 */ private static void level(@NotNull StringBuilder builder, @NotNull LogLevel level) { - format(builder, "bold"); + if (isFeatureEnabled("level")) { + format(builder, "bold"); - builder.append(switch (level) { - case DIAGNOSTIC -> "DIAG"; - case VERBOSE -> "VERB"; - case SILENT_WARNING -> "SARN"; - case INFORMATIONAL -> "INFO"; - case WARNING -> "WARN"; - case ERROR -> "ERR!"; - case CRASH -> "CRSH"; - }); + builder.append(switch (level) { + case DIAGNOSTIC -> "DIAG"; + case VERBOSE -> "VERB"; + case SILENT_WARNING -> "SARN"; + case INFORMATIONAL -> "INFO"; + case WARNING -> "WARN"; + case ERROR -> "ERR!"; + case CRASH -> "CRSH"; + }); - format(builder, level); + format(builder, level); + } } /** @@ -275,8 +282,6 @@ public final class Processor { builder.append(classNameSplit[classNameSplit.length - 1]); } else builder.append(issuer.getClassName()); - - format(builder, level); } /**