Skip to content

Json 格式化

Version 1.3.1

默认情况下,如果直接将对象作为日志打印内容,则会出现以下错误:

logcat.d(UserBean("Xiao Ming", "123456789"))

Json 转换错误

LogJson 允许你将对象以 json 的形式打印:

val gson = GsonConverter.getInstance(true)

val logFactory: LogFactory = getLogFactory {
    ...
    install(LogJson) {
        converter = gson
    }
}

以下是成功打印示例:

Json 转换

添加依赖

version

implementation("com.google.code.gson:gson:$version")

version

implementation("com.alibaba.fastjson2:fastjson2:$version")

version

implementation("com.fasterxml.jackson.core:jackson-databind:$version")