Add newline indent for multiline log messages
This commit is contained in:
parent
b7772f5fb8
commit
b0c3473c83
4 changed files with 31 additions and 3 deletions
|
@ -31,7 +31,7 @@ interface Adapter {
|
||||||
/**
|
/**
|
||||||
* Handles the processed log call.
|
* 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!)
|
* @param format finalized log format (print this!)
|
||||||
* @since v1-alpha10
|
* @since v1-alpha10
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -26,7 +26,7 @@ import de.staropensource.engine.base.type.logging.Feature
|
||||||
/**
|
/**
|
||||||
* Builds log formats.
|
* 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
|
* @since v1-alpha10
|
||||||
*/
|
*/
|
||||||
abstract class FormatBuilder(protected val call: Call) {
|
abstract class FormatBuilder(protected val call: Call) {
|
||||||
|
@ -74,6 +74,15 @@ abstract class FormatBuilder(protected val call: Call) {
|
||||||
enabledFeatures.remove(feature)
|
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.
|
* Returns the finalized format.
|
||||||
*
|
*
|
||||||
|
|
|
@ -42,6 +42,21 @@ import kotlinx.datetime.toLocalDateTime
|
||||||
*/
|
*/
|
||||||
open class SOSLSv2FormatBuilder(call: Call) : FormatBuilder(call) {
|
open class SOSLSv2FormatBuilder(call: Call) : FormatBuilder(call) {
|
||||||
override fun toString(): String {
|
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()
|
val format: StringBuilder = StringBuilder()
|
||||||
|
|
||||||
addRuntime(format)
|
addRuntime(format)
|
||||||
|
@ -58,7 +73,8 @@ open class SOSLSv2FormatBuilder(call: Call) : FormatBuilder(call) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Message
|
// Message
|
||||||
format.append(message)
|
if (message)
|
||||||
|
format.append(this.message)
|
||||||
|
|
||||||
return format.toString()
|
return format.toString()
|
||||||
}
|
}
|
||||||
|
|
|
@ -125,6 +125,9 @@ class Processor private constructor() {
|
||||||
&& EngineConfiguration.logFeatures.contains(Feature.FORMATTING)
|
&& EngineConfiguration.logFeatures.contains(Feature.FORMATTING)
|
||||||
) format.addFeature(Feature.FORMATTING)
|
) format.addFeature(Feature.FORMATTING)
|
||||||
|
|
||||||
|
// Add shadow
|
||||||
|
message = message.replace("\n", "\n${" ".repeat(format.toStringShadow())}")
|
||||||
|
|
||||||
// Set message
|
// Set message
|
||||||
format.message = message
|
format.message = message
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue