Update logcat logging.

This commit is contained in:
Greyson Parrelli
2025-02-26 15:23:32 -05:00
parent 6d294cd710
commit 0c146ef35c
2 changed files with 60 additions and 38 deletions

View File

@@ -1,38 +0,0 @@
package org.signal.core.util.logging;
import android.annotation.SuppressLint;
import org.signal.core.util.logging.Log;
@SuppressLint("LogNotSignal")
public final class AndroidLogger extends Log.Logger {
@Override
public void v(String tag, String message, Throwable t, boolean keepLonger) {
android.util.Log.v(tag, message, t);
}
@Override
public void d(String tag, String message, Throwable t, boolean keepLonger) {
android.util.Log.d(tag, message, t);
}
@Override
public void i(String tag, String message, Throwable t, boolean keepLonger) {
android.util.Log.i(tag, message, t);
}
@Override
public void w(String tag, String message, Throwable t, boolean keepLonger) {
android.util.Log.w(tag, message, t);
}
@Override
public void e(String tag, String message, Throwable t, boolean keepLonger) {
android.util.Log.e(tag, message, t);
}
@Override
public void flush() {
}
}

View File

@@ -0,0 +1,60 @@
package org.signal.core.util.logging
import android.annotation.SuppressLint
import java.util.concurrent.CountDownLatch
import java.util.concurrent.Executor
import java.util.concurrent.Executors
@SuppressLint("LogNotSignal")
class AndroidLogger : Log.Logger() {
private val serialExecutor: Executor = Executors.newSingleThreadExecutor { Thread(it, "signal-logcat") }
override fun v(tag: String, message: String?, t: Throwable?, keepLonger: Boolean) {
serialExecutor.execute {
android.util.Log.v(tag, message.scrub(), t)
}
}
override fun d(tag: String, message: String?, t: Throwable?, keepLonger: Boolean) {
serialExecutor.execute {
android.util.Log.d(tag, message.scrub(), t)
}
}
override fun i(tag: String, message: String?, t: Throwable?, keepLonger: Boolean) {
serialExecutor.execute {
android.util.Log.i(tag, message.scrub(), t)
}
}
override fun w(tag: String, message: String?, t: Throwable?, keepLonger: Boolean) {
serialExecutor.execute {
android.util.Log.w(tag, message.scrub(), t)
}
}
override fun e(tag: String, message: String?, t: Throwable?, keepLonger: Boolean) {
serialExecutor.execute {
android.util.Log.e(tag, message.scrub(), t)
}
}
override fun flush() {
val latch = CountDownLatch(1)
serialExecutor.execute {
latch.countDown()
}
try {
latch.await()
} catch (e: InterruptedException) {
android.util.Log.w("AndroidLogger", "Interrupted while waiting for flush()", e)
}
}
private fun String?.scrub(): String? {
return this?.let { Scrubber.scrub(it).toString() }
}
}