Skip to content

Commit

Permalink
Add the CallWebView logs to our logging stack (#3637)
Browse files Browse the repository at this point in the history
* Add the `CallWebView` logs to our logging stack

---

Co-Authored by @bmarty
  • Loading branch information
jmartinesp authored Oct 10, 2024
1 parent 366db47 commit c6d3ad8
Showing 1 changed file with 22 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
package io.element.android.features.call.impl.ui

import android.annotation.SuppressLint
import android.util.Log
import android.view.ViewGroup
import android.webkit.ConsoleMessage
import android.webkit.PermissionRequest
import android.webkit.WebChromeClient
import android.webkit.WebView
Expand Down Expand Up @@ -43,6 +45,7 @@ import io.element.android.libraries.designsystem.theme.components.Scaffold
import io.element.android.libraries.designsystem.theme.components.Text
import io.element.android.libraries.designsystem.theme.components.TopAppBar
import io.element.android.libraries.ui.strings.CommonStrings
import timber.log.Timber

typealias RequestPermissionCallback = (Array<String>) -> Unit

Expand Down Expand Up @@ -189,6 +192,25 @@ private fun WebView.setup(
override fun onPermissionRequest(request: PermissionRequest) {
onPermissionsRequested(request)
}

override fun onConsoleMessage(consoleMessage: ConsoleMessage): Boolean {
val priority = when (consoleMessage.messageLevel()) {
ConsoleMessage.MessageLevel.ERROR -> Log.ERROR
ConsoleMessage.MessageLevel.WARNING -> Log.WARN
else -> Log.DEBUG
}
Timber.tag("WebView").log(
priority = priority,
message = buildString {
append(consoleMessage.sourceId())
append(":")
append(consoleMessage.lineNumber())
append(" ")
append(consoleMessage.message())
},
)
return true
}
}
}

Expand Down

0 comments on commit c6d3ad8

Please sign in to comment.