mirror of
https://github.com/signalapp/Signal-Android.git
synced 2026-04-20 08:39:22 +01:00
Update logcat logging.
This commit is contained in:
@@ -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() {
|
||||
}
|
||||
}
|
||||
@@ -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() }
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user