Переглянути джерело

请求日志支持JSON/Text类型输出

drake 3 роки тому
батько
коміт
3833e0390b

+ 2 - 2
net/src/main/java/com/drake/net/interceptor/LogRecordInterceptor.kt

@@ -20,8 +20,8 @@ import okhttp3.Response
  * 在正式环境下请禁用此日志记录器. 因为他会消耗少量网络速度
  *
  * @property enabled 是否启用日志输出
- * @property requestByteCount 请求日志输出字节数
- * @property responseByteCount 响应日志输出字节数
+ * @property requestByteCount 请求日志输出字节数, -1 则为全部
+ * @property responseByteCount 响应日志输出字节数, -1 则为全部
  */
 open class LogRecordInterceptor(
     private val enabled: Boolean,

+ 2 - 2
net/src/main/java/com/drake/net/request/RequestExtension.kt

@@ -179,11 +179,11 @@ fun Request.Builder.setConverter(converter: NetConverter) = apply {
 
 /**
  * 请求日志信息
- * 只会输出纯表单(form)的请求参数
+ * 只会输出 application/x-www-form-urlencoded, application/json, text/`*` 的请求体类型日志
  */
 fun Request.logString(byteCount: Long = 1024 * 1024): String? {
     val mediaType = body?.contentType() ?: return null
-    return if (body is FormBody) {
+    return if (body is FormBody || mediaType.type == "text" || mediaType.subtype == "json") {
         body?.peekString(byteCount)
     } else {
         "LogRecordInterceptor not support this type $mediaType"

+ 1 - 1
net/src/main/java/com/drake/net/response/ResponseExtention.kt

@@ -114,7 +114,7 @@ fun Response.file(): File? {
 
 /**
  * 响应日志信息
- * 只会输出JSON(application/json)和文本(text/\*)字符串日志
+ * 只会输出 application/json, text/`*` 响应体类型日志
  */
 fun Response.logString(byteCount: Long = 1024 * 1024 * 4): String? {
     val mediaType = body?.contentType() ?: return null