diff --git a/changelog.d/6925.misc b/changelog.d/6925.misc new file mode 100644 index 0000000000..f494b76b56 --- /dev/null +++ b/changelog.d/6925.misc @@ -0,0 +1 @@ +Log basic Http information in production. diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/di/NetworkModule.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/di/NetworkModule.kt index 113e780e5c..cb2088a145 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/di/NetworkModule.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/di/NetworkModule.kt @@ -42,7 +42,7 @@ internal object NetworkModule { @Provides @JvmStatic fun providesHttpLoggingInterceptor(): HttpLoggingInterceptor { - val logger = FormattedJsonHttpLogger() + val logger = FormattedJsonHttpLogger(BuildConfig.OKHTTP_LOGGING_LEVEL) val interceptor = HttpLoggingInterceptor(logger) interceptor.level = BuildConfig.OKHTTP_LOGGING_LEVEL return interceptor diff --git a/matrix-sdk-android/src/debug/java/org/matrix/android/sdk/internal/network/interceptors/FormattedJsonHttpLogger.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/network/interceptors/FormattedJsonHttpLogger.kt similarity index 84% rename from matrix-sdk-android/src/debug/java/org/matrix/android/sdk/internal/network/interceptors/FormattedJsonHttpLogger.kt rename to matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/network/interceptors/FormattedJsonHttpLogger.kt index 2661bd1f70..4e0525536c 100644 --- a/matrix-sdk-android/src/debug/java/org/matrix/android/sdk/internal/network/interceptors/FormattedJsonHttpLogger.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/network/interceptors/FormattedJsonHttpLogger.kt @@ -23,15 +23,17 @@ import org.json.JSONException import org.json.JSONObject import timber.log.Timber -internal class FormattedJsonHttpLogger : HttpLoggingInterceptor.Logger { +internal class FormattedJsonHttpLogger( + private val level: HttpLoggingInterceptor.Level +) : HttpLoggingInterceptor.Logger { companion object { private const val INDENT_SPACE = 2 } /** - * 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 + * 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. * * @param message */ @@ -39,6 +41,10 @@ internal class FormattedJsonHttpLogger : HttpLoggingInterceptor.Logger { override fun log(@NonNull message: String) { 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("{")) { // JSON Detected try { diff --git a/matrix-sdk-android/src/release/java/org/matrix/android/sdk/internal/network/interceptors/FormattedJsonHttpLogger.kt b/matrix-sdk-android/src/release/java/org/matrix/android/sdk/internal/network/interceptors/FormattedJsonHttpLogger.kt deleted file mode 100644 index a815cec353..0000000000 --- a/matrix-sdk-android/src/release/java/org/matrix/android/sdk/internal/network/interceptors/FormattedJsonHttpLogger.kt +++ /dev/null @@ -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) { - } -}