improve logging performance

This commit is contained in:
Bixilon 2021-04-27 18:07:23 +02:00
parent 4e6013ed92
commit 8f2edfcc75
No known key found for this signature in database
GPG Key ID: 5CAD791931B09AC4
2 changed files with 10 additions and 8 deletions

View File

@ -67,7 +67,7 @@ interface ChatComponent {
companion object {
@JvmOverloads
fun of(raw: Any?, translator: Translator? = null, parent: TextComponent? = null): ChatComponent {
fun of(raw: Any?, translator: Translator? = null, parent: TextComponent? = null, ignoreJson: Boolean = false): ChatComponent {
if (raw == null) {
return BaseComponent()
}
@ -88,9 +88,11 @@ interface ChatComponent {
is JsonPrimitive -> raw.asString
else -> raw.toString()
}
try {
return BaseComponent(translator, parent, JsonParser.parseString(string).asJsonObject)
} catch (ignored: RuntimeException) {
if (!ignoreJson) {
try {
return BaseComponent(translator, parent, JsonParser.parseString(string).asJsonObject)
} catch (ignored: RuntimeException) {
}
}
return BaseComponent(parent, string)

View File

@ -100,16 +100,16 @@ object Log {
is Throwable -> {
val stringWriter = StringWriter()
message.printStackTrace(PrintWriter(stringWriter))
ChatComponent.of(stringWriter.toString())
ChatComponent.of(stringWriter.toString(), ignoreJson = true)
}
is String -> {
if (formatting.isNotEmpty()) {
ChatComponent.of(message.format(*formatting))
ChatComponent.of(message.format(*formatting), ignoreJson = true)
} else {
ChatComponent.of(message)
ChatComponent.of(message, ignoreJson = true)
}
}
else -> ChatComponent.of(message)
else -> ChatComponent.of(message, ignoreJson = true)
}
LOG_QUEUE.add(