Skip to content

Commit

Permalink
fix: Filter logs correctly
Browse files Browse the repository at this point in the history
BREAKING CHANGE: This changes the log handler signature
  • Loading branch information
oSumAtrIX committed Sep 20, 2023
1 parent e3851d5 commit 43fc20d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
2 changes: 1 addition & 1 deletion revanced-lib/api/revanced-lib.api
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public final class app/revanced/lib/adb/AdbManager$UserAdbManager : app/revanced

public final class app/revanced/lib/logging/Logger {
public static final field INSTANCE Lapp/revanced/lib/logging/Logger;
public final fun addHandler (Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function0;Lkotlin/jvm/functions/Function0;)V
public final fun addHandler (Lkotlin/jvm/functions/Function3;Lkotlin/jvm/functions/Function0;Lkotlin/jvm/functions/Function0;)V
public final fun removeAllHandlers ()V
public final fun setDefault ()V
public final fun setFormat (Ljava/lang/String;)V
Expand Down
12 changes: 9 additions & 3 deletions revanced-lib/src/main/kotlin/app/revanced/lib/logging/Logger.kt
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,15 @@ object Logger {
* @param closeHandler The handler for closing the log.
*/
fun addHandler(
publishHandler: (log: String, level: Level) -> Unit,
publishHandler: (log: String, level: Level, loggerName: String?) -> Unit,
flushHandler: () -> Unit,
closeHandler: () -> Unit
) = object : Handler() {
override fun publish(record: LogRecord) = publishHandler(formatter.format(record), record.level)
override fun publish(record: LogRecord) = publishHandler(
formatter.format(record),
record.level,
record.loggerName
)

override fun flush() = flushHandler()

Expand All @@ -59,7 +63,9 @@ object Logger {
setFormat()
removeAllHandlers()

val publishHandler = { log: String, level: Level ->
val publishHandler = handler@{ log: String, level: Level, loggerName: String? ->
if (loggerName?.startsWith("app.revanced") != true) return@handler

log.toByteArray().let {
if (level.intValue() > Level.INFO.intValue())
System.err.write(it)
Expand Down

0 comments on commit 43fc20d

Please sign in to comment.