File tree Expand file tree Collapse file tree 1 file changed +17
-2
lines changed
app/src/main/java/to/bitkit/utils Expand file tree Collapse file tree 1 file changed +17
-2
lines changed Original file line number Diff line number Diff line change @@ -6,6 +6,10 @@ import kotlinx.coroutines.Dispatchers
66import kotlinx.coroutines.SupervisorJob
77import kotlinx.coroutines.launch
88import kotlinx.serialization.json.Json
9+ import kotlinx.serialization.json.JsonObject
10+ import kotlinx.serialization.json.buildJsonObject
11+ import kotlinx.serialization.json.encodeToJsonElement
12+ import kotlinx.serialization.json.put
913import kotlinx.serialization.serializer
1014import org.lightningdevkit.ldknode.LogRecord
1115import org.lightningdevkit.ldknode.LogWriter
@@ -336,8 +340,19 @@ val jsonLogger = Json(json) {
336340 prettyPrint = false
337341}
338342
339- inline fun <reified T > jsonLogOf (value : T ): String = with (jsonLogger) {
340- encodeToString(serializersModule.serializer(), value)
343+ inline fun <reified T : Any > jsonLogOf (value : T ): String {
344+ val jsonElement = jsonLogger.encodeToJsonElement(jsonLogger.serializersModule.serializer<T >(), value)
345+ if (jsonElement !is JsonObject || " type" !in jsonElement) return jsonElement.toString()
346+
347+ return buildJsonObject {
348+ jsonElement.forEach { (key, elem) ->
349+ if (key == " type" ) {
350+ put(" type" , value::class .simpleName ? : " Unknown" )
351+ } else {
352+ put(key, elem)
353+ }
354+ }
355+ }.toString()
341356}
342357
343358fun errLogOf (e : Throwable ): String = " [${e::class .simpleName} ='${e.message} ']"
You can’t perform that action at this time.
0 commit comments