Commit 02890a54 authored by Grisha Kruglov's avatar Grisha Kruglov
Browse files

Closes #7255 - Optionally submit errors as caught exceptions in RustLog

parent faca3671
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -31,6 +31,7 @@ dependencies {
    implementation Dependencies.mozilla_rustlog

    implementation Dependencies.kotlin_stdlib
    implementation Dependencies.kotlin_coroutines
    // Log.Priority is in the public api.
    api project(':support-base')

+15 −2
Original line number Diff line number Diff line
@@ -6,8 +6,11 @@ package mozilla.components.support.rustlog

import mozilla.appservices.rustlog.LogLevelFilter
import mozilla.appservices.rustlog.RustLogAdapter
import mozilla.components.support.base.crash.CrashReporting
import mozilla.components.support.base.log.Log

internal class RustErrorException(tag: String?, msg: String) : Exception("$tag - $msg")

object RustLog {

    /**
@@ -29,10 +32,20 @@ object RustLog {
     * (We say "almost" nothing, as calling this will hook up logging for the dynamic
     * library containing the Rust log hooking (and only that), as well as logging
     * a single message indicating that it completed initialization).
     *
     * @param crashReporter [CrashReporting] instance used for reporting 'error' log messages.
     */
    fun enable() {
    fun enable(crashReporter: CrashReporting? = null) {
        RustLogAdapter.enable { level, tagStr, msgStr ->
            Log.log(levelToPriority(level), tagStr, null, msgStr)
            val priority = levelToPriority(level)

            crashReporter?.let {
                if (priority == Log.Priority.ERROR) {
                    it.submitCaughtException(RustErrorException(tagStr, msgStr))
                }
            }

            Log.log(priority, tagStr, null, msgStr)
            // Return true to keep open. Eventually we could intercept calls
            // to disable that happen as the direct result of the above call
            // (e.g. on this thread, before this function returns) and return
+3 −0
Original line number Diff line number Diff line
@@ -28,6 +28,9 @@ permalink: /changelog/
* **local development**
  * Enable local Gradle Build Cache to speed-up local builds. Build cache is located in `.build-cache/`, clear it if you run into strange problems and please file an issue.

* **support-rustlog**
  * `RustLog.enable` now takes an optional [CrashReporting] instance which is used to submit error-level log messages as `RustErrorException`s.

# 44.0.0

* [Commits](https://github.com/mozilla-mobile/android-components/compare/v43.0.0...v44.0.0)