Merge pull request #6925 from vector-im/feature/bma/http_log
Feature/bma/http log
This commit is contained in:
commit
51dcaf7556
1
changelog.d/6925.misc
Normal file
1
changelog.d/6925.misc
Normal file
@ -0,0 +1 @@
|
|||||||
|
Log basic Http information in production.
|
@ -42,7 +42,7 @@ internal object NetworkModule {
|
|||||||
@Provides
|
@Provides
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
fun providesHttpLoggingInterceptor(): HttpLoggingInterceptor {
|
fun providesHttpLoggingInterceptor(): HttpLoggingInterceptor {
|
||||||
val logger = FormattedJsonHttpLogger()
|
val logger = FormattedJsonHttpLogger(BuildConfig.OKHTTP_LOGGING_LEVEL)
|
||||||
val interceptor = HttpLoggingInterceptor(logger)
|
val interceptor = HttpLoggingInterceptor(logger)
|
||||||
interceptor.level = BuildConfig.OKHTTP_LOGGING_LEVEL
|
interceptor.level = BuildConfig.OKHTTP_LOGGING_LEVEL
|
||||||
return interceptor
|
return interceptor
|
||||||
|
@ -23,15 +23,17 @@ import org.json.JSONException
|
|||||||
import org.json.JSONObject
|
import org.json.JSONObject
|
||||||
import timber.log.Timber
|
import timber.log.Timber
|
||||||
|
|
||||||
internal class FormattedJsonHttpLogger : HttpLoggingInterceptor.Logger {
|
internal class FormattedJsonHttpLogger(
|
||||||
|
private val level: HttpLoggingInterceptor.Level
|
||||||
|
) : HttpLoggingInterceptor.Logger {
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
private const val INDENT_SPACE = 2
|
private const val INDENT_SPACE = 2
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Log the message and try to log it again as a JSON formatted string
|
* Log the message and try to log it again as a JSON formatted string.
|
||||||
* Note: it can consume a lot of memory but it is only in DEBUG mode
|
* Note: it can consume a lot of memory but it is only in DEBUG mode.
|
||||||
*
|
*
|
||||||
* @param message
|
* @param message
|
||||||
*/
|
*/
|
||||||
@ -39,6 +41,10 @@ internal class FormattedJsonHttpLogger : HttpLoggingInterceptor.Logger {
|
|||||||
override fun log(@NonNull message: String) {
|
override fun log(@NonNull message: String) {
|
||||||
Timber.v(message)
|
Timber.v(message)
|
||||||
|
|
||||||
|
// Try to log formatted Json only if there is a chance that [message] contains Json.
|
||||||
|
// It can be only the case if we log the bodies of Http requests.
|
||||||
|
if (level != HttpLoggingInterceptor.Level.BODY) return
|
||||||
|
|
||||||
if (message.startsWith("{")) {
|
if (message.startsWith("{")) {
|
||||||
// JSON Detected
|
// JSON Detected
|
||||||
try {
|
try {
|
@ -1,30 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2020 The Matrix.org Foundation C.I.C.
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package org.matrix.android.sdk.internal.network.interceptors
|
|
||||||
|
|
||||||
import androidx.annotation.NonNull
|
|
||||||
import okhttp3.logging.HttpLoggingInterceptor
|
|
||||||
|
|
||||||
/**
|
|
||||||
* No op logger
|
|
||||||
*/
|
|
||||||
internal class FormattedJsonHttpLogger : HttpLoggingInterceptor.Logger {
|
|
||||||
|
|
||||||
@Synchronized
|
|
||||||
override fun log(@NonNull message: String) {
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
x
Reference in New Issue
Block a user