From b0c3473c83435cefb9c2a60e0b0af2c17119d973 Mon Sep 17 00:00:00 2001 From: JeremyStarTM Date: Tue, 17 Dec 2024 19:58:36 +0100 Subject: [PATCH] Add newline indent for multiline log messages --- .../base/implementable/logging/Adapter.kt | 2 +- .../implementable/logging/FormatBuilder.kt | 11 ++++++++++- .../formatbuilder/SOSLSv2FormatBuilder.kt | 18 +++++++++++++++++- .../engine/base/logging/Processor.kt | 3 +++ 4 files changed, 31 insertions(+), 3 deletions(-) diff --git a/base/src/main/kotlin/de/staropensource/engine/base/implementable/logging/Adapter.kt b/base/src/main/kotlin/de/staropensource/engine/base/implementable/logging/Adapter.kt index 2d0cb48..9c7d771 100644 --- a/base/src/main/kotlin/de/staropensource/engine/base/implementable/logging/Adapter.kt +++ b/base/src/main/kotlin/de/staropensource/engine/base/implementable/logging/Adapter.kt @@ -31,7 +31,7 @@ interface Adapter { /** * Handles the processed log call. * - * @param call original [de.staropensource.engine.logging.type.Call] + * @param call original [Call] * @param format finalized log format (print this!) * @since v1-alpha10 */ diff --git a/base/src/main/kotlin/de/staropensource/engine/base/implementable/logging/FormatBuilder.kt b/base/src/main/kotlin/de/staropensource/engine/base/implementable/logging/FormatBuilder.kt index 369f448..6a6b325 100644 --- a/base/src/main/kotlin/de/staropensource/engine/base/implementable/logging/FormatBuilder.kt +++ b/base/src/main/kotlin/de/staropensource/engine/base/implementable/logging/FormatBuilder.kt @@ -26,7 +26,7 @@ import de.staropensource.engine.base.type.logging.Feature /** * Builds log formats. * - * @param call [de.staropensource.engine.logging.type.Call] to build a format for + * @param call [Call] to build a format for * @since v1-alpha10 */ abstract class FormatBuilder(protected val call: Call) { @@ -74,6 +74,15 @@ abstract class FormatBuilder(protected val call: Call) { enabledFeatures.remove(feature) } + /** + * Returns the size of the finalized + * format without the message. + * + * @return size of the finalized format without the message + * @since v1-alpha10 + */ + abstract fun toStringShadow(): Int + /** * Returns the finalized format. * diff --git a/base/src/main/kotlin/de/staropensource/engine/base/implementation/logging/formatbuilder/SOSLSv2FormatBuilder.kt b/base/src/main/kotlin/de/staropensource/engine/base/implementation/logging/formatbuilder/SOSLSv2FormatBuilder.kt index 65c2868..d0ff786 100644 --- a/base/src/main/kotlin/de/staropensource/engine/base/implementation/logging/formatbuilder/SOSLSv2FormatBuilder.kt +++ b/base/src/main/kotlin/de/staropensource/engine/base/implementation/logging/formatbuilder/SOSLSv2FormatBuilder.kt @@ -42,6 +42,21 @@ import kotlinx.datetime.toLocalDateTime */ open class SOSLSv2FormatBuilder(call: Call) : FormatBuilder(call) { override fun toString(): String { + return format(message = true) + } + + override fun toStringShadow(): Int { + return format(message = false).length + } + + /** + * Runs the actual formatting step. + * + * @param message add the message to the finalized format? + * @return finalized format + * @since v1-alpha10 + */ + fun format(message: Boolean): String { val format: StringBuilder = StringBuilder() addRuntime(format) @@ -58,7 +73,8 @@ open class SOSLSv2FormatBuilder(call: Call) : FormatBuilder(call) { } // Message - format.append(message) + if (message) + format.append(this.message) return format.toString() } diff --git a/base/src/main/kotlin/de/staropensource/engine/base/logging/Processor.kt b/base/src/main/kotlin/de/staropensource/engine/base/logging/Processor.kt index e620ee5..8bd51a4 100644 --- a/base/src/main/kotlin/de/staropensource/engine/base/logging/Processor.kt +++ b/base/src/main/kotlin/de/staropensource/engine/base/logging/Processor.kt @@ -125,6 +125,9 @@ class Processor private constructor() { && EngineConfiguration.logFeatures.contains(Feature.FORMATTING) ) format.addFeature(Feature.FORMATTING) + // Add shadow + message = message.replace("\n", "\n${" ".repeat(format.toStringShadow())}") + // Set message format.message = message