From f815af8ac1ae24a92942f09cfd388b877d0cef27 Mon Sep 17 00:00:00 2001 From: jjzazuet Date: Sun, 27 Oct 2024 10:56:20 -0400 Subject: [PATCH] - Rendering kv primitive arguments in message body. - Patch version bump. --- build.gradle.kts | 2 +- src/main/java/io/vacco/shax/logging/ShArgument.java | 13 ++++++++++--- src/test/java/io/vacco/shax/test/ShLoggerSpec.java | 2 +- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index c743436..7409a25 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,7 +1,7 @@ plugins { id("io.vacco.oss.gitflow") version "1.0.1" } group = "io.vacco.shax" -version = "2.0.16.0.4.0" +version = "2.0.16.0.4.1" configure { addJ8Spec() diff --git a/src/main/java/io/vacco/shax/logging/ShArgument.java b/src/main/java/io/vacco/shax/logging/ShArgument.java index f2d8aa4..7c3a165 100644 --- a/src/main/java/io/vacco/shax/logging/ShArgument.java +++ b/src/main/java/io/vacco/shax/logging/ShArgument.java @@ -1,6 +1,7 @@ package io.vacco.shax.logging; import java.util.Objects; +import static io.vacco.shax.json.ShReflect.*; public class ShArgument { @@ -15,9 +16,15 @@ public static ShArgument kv(String key, Object value) { } @Override public String toString() { - return String.format("{%s=%s}", - key, value != null ? value.getClass().getCanonicalName() : "null" - ); + String v = "null"; + if (value != null) { + if (isBaseType(value) && !isCollection(value)) { + v = value.toString(); + } else { + v = value.getClass().getCanonicalName(); + } + } + return String.format("{%s=%s}", key, v); } } diff --git a/src/test/java/io/vacco/shax/test/ShLoggerSpec.java b/src/test/java/io/vacco/shax/test/ShLoggerSpec.java index f1a86da..f66c921 100644 --- a/src/test/java/io/vacco/shax/test/ShLoggerSpec.java +++ b/src/test/java/io/vacco/shax/test/ShLoggerSpec.java @@ -66,7 +66,7 @@ public class ShLoggerSpec { e("Chi", "Youhei") ); - log.info("Cats and Owners [{}]", kv("catOwners", catOwners)); + log.info("Cats and Owners {}", kv("catOwners", catOwners)); log.info("Boolean log {}", kv("boolVal", true)); log.info("Integer log {}", kv("intVal", 42)); log.info("Long log {}", kv("longVal", 42L));