From cd6abadfae55b6b6e9a8acf37a979ef3d97254f3 Mon Sep 17 00:00:00 2001 From: Igor Date: Mon, 18 Mar 2024 09:34:32 +0300 Subject: [PATCH] fix size grpc log --- README.md | 16 ++++++++-------- .../loggers/data/models/NetworkLogEntity.kt | 10 +++++----- dependencies.gradle | 2 +- .../networklog/grpc/FinchClientInterceptor.kt | 4 ++++ sample/build.gradle | 12 ++++++------ 5 files changed, 24 insertions(+), 20 deletions(-) diff --git a/README.md b/README.md index d6061d3..bc04fda 100644 --- a/README.md +++ b/README.md @@ -27,17 +27,17 @@ Pick a UI implementation and add the dependency: ````java dependencies { - debugImplementation 'com.github.kernel0x.finch:ui-drawer:2.2.8' - releaseImplementation 'com.github.kernel0x.finch:noop:2.2.8' + debugImplementation 'com.github.kernel0x.finch:ui-drawer:2.2.9' + releaseImplementation 'com.github.kernel0x.finch:noop:2.2.9' // optional only for OkHttp - debugImplementation 'com.github.kernel0x.finch:log-okhttp:2.2.8' - releaseImplementation 'com.github.kernel0x.finch:log-okhttp-noop:2.2.8' + debugImplementation 'com.github.kernel0x.finch:log-okhttp:2.2.9' + releaseImplementation 'com.github.kernel0x.finch:log-okhttp-noop:2.2.9' // optional only for GRPC - debugImplementation 'com.github.kernel0x.finch:log-grpc:2.2.8' - releaseImplementation 'com.github.kernel0x.finch:log-grpc-noop:2.2.8' + debugImplementation 'com.github.kernel0x.finch:log-grpc:2.2.9' + releaseImplementation 'com.github.kernel0x.finch:log-grpc-noop:2.2.9' // optional only for logs - debugImplementation 'com.github.kernel0x.finch:log:2.2.8' - releaseImplementation 'com.github.kernel0x.finch:log-noop:2.2.8' + debugImplementation 'com.github.kernel0x.finch:log:2.2.9' + releaseImplementation 'com.github.kernel0x.finch:log-noop:2.2.9' } ```` diff --git a/common-loggers/src/main/java/com/kernel/finch/common/loggers/data/models/NetworkLogEntity.kt b/common-loggers/src/main/java/com/kernel/finch/common/loggers/data/models/NetworkLogEntity.kt index 21e349e..9f01b6f 100755 --- a/common-loggers/src/main/java/com/kernel/finch/common/loggers/data/models/NetworkLogEntity.kt +++ b/common-loggers/src/main/java/com/kernel/finch/common/loggers/data/models/NetworkLogEntity.kt @@ -102,7 +102,7 @@ data class NetworkLogEntity( } } - fun getDurationString(): String? { + fun getDurationString(): String { return "$duration ms" } @@ -110,7 +110,7 @@ data class NetworkLogEntity( return formatBytes(requestContentLength) } - fun getResponseSizeString(): String? { + fun getResponseSizeString(): String { return formatBytes(responseContentLength) } @@ -135,15 +135,15 @@ data class NetworkLogEntity( } fun isSsl(): Boolean { - return scheme.toLowerCase(Locale.getDefault()) == "https" + return scheme.lowercase(Locale.getDefault()) == "https" } private fun formatBody(body: String, contentType: String?): String { - return if (contentType != null && contentType.toLowerCase(Locale.getDefault()) + return if (contentType != null && contentType.lowercase(Locale.getDefault()) .contains("json") ) { FormatUtil.formatJson(body) - } else if (contentType != null && contentType.toLowerCase(Locale.getDefault()) + } else if (contentType != null && contentType.lowercase(Locale.getDefault()) .contains("xml") ) { FormatUtil.formatXml(body) diff --git a/dependencies.gradle b/dependencies.gradle index 510924d..4d79632 100644 --- a/dependencies.gradle +++ b/dependencies.gradle @@ -2,7 +2,7 @@ ext.versions = [ minSdk : 21, targetSdk : 34, compileSdk : 34, - libraryVersion : '2.2.8', + libraryVersion : '2.2.9', libraryVersionCode: 15, okhttp3 : '3.7.0', diff --git a/log-grpc/src/main/java/com/kernel/finch/networklog/grpc/FinchClientInterceptor.kt b/log-grpc/src/main/java/com/kernel/finch/networklog/grpc/FinchClientInterceptor.kt index 2a11432..6b04d56 100644 --- a/log-grpc/src/main/java/com/kernel/finch/networklog/grpc/FinchClientInterceptor.kt +++ b/log-grpc/src/main/java/com/kernel/finch/networklog/grpc/FinchClientInterceptor.kt @@ -56,6 +56,8 @@ internal class FinchClientInterceptor : ClientInterceptor { TextFormat.printer().escapingNonAscii(false).printToString( message as MessageOrBuilder ) + networkLog.responseContentLength = + networkLog.responseBody.toByteArray().size.toLong() FinchGrpcLogger.logNetworkEvent(networkLog) super.onMessage(message) } @@ -89,6 +91,8 @@ internal class FinchClientInterceptor : ClientInterceptor { networkLog.requestBody = TextFormat.printer().escapingNonAscii(false).printToString( message as MessageOrBuilder ) + networkLog.requestContentLength = + networkLog.requestBody.toByteArray().size.toLong() FinchGrpcLogger.logNetworkEvent(networkLog) super.sendMessage(message) } diff --git a/sample/build.gradle b/sample/build.gradle index c4d2029..a252827 100644 --- a/sample/build.gradle +++ b/sample/build.gradle @@ -29,12 +29,12 @@ android { } dependencies { - //debugImplementation 'com.github.kernel0x.finch:ui-drawer:2.2.8' - //releaseImplementation 'com.github.kernel0x.finch:noop:2.2.8' - //debugImplementation 'com.github.kernel0x.finch:log-okhttp:2.2.8' - //releaseImplementation 'com.github.kernel0x.finch:log-okhttp-noop:2.2.8' - //debugImplementation 'com.github.kernel0x.finch:log:2.2.8' - //releaseImplementation 'com.github.kernel0x.finch:log-noop:2.2.8' + //debugImplementation 'com.github.kernel0x.finch:ui-drawer:2.2.9' + //releaseImplementation 'com.github.kernel0x.finch:noop:2.2.9' + //debugImplementation 'com.github.kernel0x.finch:log-okhttp:2.2.9' + //releaseImplementation 'com.github.kernel0x.finch:log-okhttp-noop:2.2.9' + //debugImplementation 'com.github.kernel0x.finch:log:2.2.9' + //releaseImplementation 'com.github.kernel0x.finch:log-noop:2.2.9' debugImplementation project(":ui-drawer") debugImplementation project(":log") debugImplementation project(":log-okhttp")