Skip to content

Commit

Permalink
fix network log
Browse files Browse the repository at this point in the history
  • Loading branch information
kernel0x committed Dec 23, 2023
1 parent c0d906d commit 73d02a2
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 23 deletions.
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,17 @@ Pick a UI implementation and add the dependency:

````java
dependencies {
debugImplementation 'com.github.kernel0x.finch:ui-drawer:2.2.3'
releaseImplementation 'com.github.kernel0x.finch:noop:2.2.3'
debugImplementation 'com.github.kernel0x.finch:ui-drawer:2.2.4'
releaseImplementation 'com.github.kernel0x.finch:noop:2.2.4'
// optional only for OkHttp
debugImplementation 'com.github.kernel0x.finch:log-okhttp:2.2.3'
releaseImplementation 'com.github.kernel0x.finch:log-okhttp-noop:2.2.3'
debugImplementation 'com.github.kernel0x.finch:log-okhttp:2.2.4'
releaseImplementation 'com.github.kernel0x.finch:log-okhttp-noop:2.2.4'
// optional only for GRPC
debugImplementation 'com.github.kernel0x.finch:log-grpc:2.2.3'
releaseImplementation 'com.github.kernel0x.finch:log-grpc-noop:2.2.3'
debugImplementation 'com.github.kernel0x.finch:log-grpc:2.2.4'
releaseImplementation 'com.github.kernel0x.finch:log-grpc-noop:2.2.4'
// optional only for logs
debugImplementation 'com.github.kernel0x.finch:log:2.2.3'
releaseImplementation 'com.github.kernel0x.finch:log-noop:2.2.3'
debugImplementation 'com.github.kernel0x.finch:log:2.2.4'
releaseImplementation 'com.github.kernel0x.finch:log-noop:2.2.4'
}
````

Expand Down
4 changes: 2 additions & 2 deletions dependencies.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ ext.versions = [
minSdk : 21,
targetSdk : 34,
compileSdk : 34,
libraryVersion : '2.2.3',
libraryVersionCode: 10,
libraryVersion : '2.2.4',
libraryVersionCode: 11,

okhttp3 : '3.7.0',
gson : '2.8.2',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,9 @@ internal class FinchClientInterceptor : ClientInterceptor {
val networkLog = NetworkLogEntity()
networkLog.requestDate = System.currentTimeMillis()
networkLog.method = methodDescriptor.type.name
networkLog.protocol = "h2"
networkLog.setUrl(
url = "https://" + channel.authority() + methodDescriptor.fullMethodName,
url = "https://" + channel.authority() + "/" + methodDescriptor.fullMethodName,
host = channel.authority(),
path = methodDescriptor.fullMethodName,
scheme = "https"
Expand All @@ -49,11 +50,6 @@ internal class FinchClientInterceptor : ClientInterceptor {
responseListener
) {
override fun onMessage(message: RespT) {
val duration =
TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - startNs)
networkLog.responseDate = System.currentTimeMillis()
networkLog.duration = duration
networkLog.protocol = "h2"
networkLog.responseBody = message.toString()
FinchGrpcLogger.logNetworkEvent(networkLog)
super.onMessage(message)
Expand All @@ -66,8 +62,15 @@ internal class FinchClientInterceptor : ClientInterceptor {
}

override fun onClose(status: Status, trailers: Metadata) {
val duration =
TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - startNs)
networkLog.responseDate = System.currentTimeMillis()
networkLog.duration = duration
networkLog.responseCode = status.code.value()
networkLog.responseMessage = status.description ?: ""
networkLog.responseMessage = status.code.name
if (status.description?.isNotEmpty() == true) {
networkLog.responseMessage += "(" + status.description + ")"
}
networkLog.setResponseHeaders(toHttpHeaderList(trailers))
FinchGrpcLogger.logNetworkEvent(networkLog)
super.onClose(status, trailers)
Expand Down
12 changes: 6 additions & 6 deletions sample/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ android {
}

dependencies {
//debugImplementation 'com.github.kernel0x.finch:ui-drawer:2.2.3'
//releaseImplementation 'com.github.kernel0x.finch:noop:2.2.3'
//debugImplementation 'com.github.kernel0x.finch:log-okhttp:2.2.3'
//releaseImplementation 'com.github.kernel0x.finch:log-okhttp-noop:2.2.3'
//debugImplementation 'com.github.kernel0x.finch:log:2.2.3'
//releaseImplementation 'com.github.kernel0x.finch:log-noop:2.2.3'
//debugImplementation 'com.github.kernel0x.finch:ui-drawer:2.2.4'
//releaseImplementation 'com.github.kernel0x.finch:noop:2.2.4'
//debugImplementation 'com.github.kernel0x.finch:log-okhttp:2.2.4'
//releaseImplementation 'com.github.kernel0x.finch:log-okhttp-noop:2.2.4'
//debugImplementation 'com.github.kernel0x.finch:log:2.2.4'
//releaseImplementation 'com.github.kernel0x.finch:log-noop:2.2.4'
debugImplementation project(":ui-drawer")
debugImplementation project(":log")
debugImplementation project(":log-okhttp")
Expand Down

0 comments on commit 73d02a2

Please sign in to comment.