Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/bma/http log #6925

Merged
merged 4 commits into from
Aug 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/6925.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Log basic Http information in production.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,22 +23,28 @@ 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
*/
@Synchronized
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 {
Expand Down

This file was deleted.