Skip to content

Commit

Permalink
Don't insert space before colon
Browse files Browse the repository at this point in the history
  • Loading branch information
orangain committed Mar 7, 2024
1 parent 2477525 commit 949b106
Showing 1 changed file with 13 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package io.github.orangain.prettyjsonlog.console

import com.fasterxml.jackson.core.JsonProcessingException
import com.fasterxml.jackson.core.util.DefaultPrettyPrinter
import com.fasterxml.jackson.databind.JsonNode
import com.fasterxml.jackson.databind.SerializationFeature
import com.fasterxml.jackson.databind.cfg.JsonNodeFeature
Expand Down Expand Up @@ -51,7 +52,7 @@ class MyConsoleInputFilter : InputFilter {
val message = messageKey?.let { node.get(it) }
?.asText()

val jsonString = mapper.writeValueAsString(node)
val jsonString = writer.writeValueAsString(node)
// return mutableListOf(
// Pair("[$timestamp] ", contentType),
// Pair(level, contentTypeOf(level, contentType)),
Expand All @@ -71,6 +72,17 @@ private val mapper = jacksonObjectMapper().apply {
configure(SerializationFeature.INDENT_OUTPUT, true)
configure(JsonNodeFeature.WRITE_PROPERTIES_SORTED, true)
}
private val writer = mapper.writer(MyPrettyPrinter())

class MyPrettyPrinter : DefaultPrettyPrinter() {
init {
_objectFieldValueSeparatorWithSpaces = ": "
}

override fun createInstance(): DefaultPrettyPrinter {
return MyPrettyPrinter()
}
}

private fun parseJson(text: String): JsonNode? {
if (!jsonPattern.matches(text)) {
Expand Down

0 comments on commit 949b106

Please sign in to comment.