Add 'level' and 'origin' log features

This commit is contained in:
JeremyStar™ 2024-12-02 20:59:47 +01:00
parent 571d600b09
commit ed1c1d3b1a
Signed by: JeremyStarTM
GPG key ID: E366BAEF67E4704D
2 changed files with 31 additions and 24 deletions

View file

@ -309,6 +309,8 @@ public final class EngineConfiguration extends Configuration {
* <li><code>moduleVersion</code> (requires <code>moduleName</code>)</li>
* <li><code>methodName</code></li>
* <li><code>lineNumber</code></li>
* <li><code>level</code></li>
* <li><code>origin</code></li>
* </ul>
*
* @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;

View file

@ -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);
}
/**