Add newline indent for multiline log messages
All checks were successful
PRs & Pushes / test (push) Successful in 3m48s
PRs & Pushes / build (push) Successful in 3m51s
PRs & Pushes / build-apidoc (push) Successful in 3m44s

This commit is contained in:
JeremyStar™ 2024-12-17 19:58:36 +01:00
parent b7772f5fb8
commit b0c3473c83
Signed by: JeremyStarTM
GPG key ID: E366BAEF67E4704D
4 changed files with 31 additions and 3 deletions

View file

@ -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
*/

View file

@ -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.
*

View file

@ -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()
}

View file

@ -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