Skip to content
This repository has been archived by the owner on Oct 15, 2024. It is now read-only.

Commit

Permalink
Fixup slf4j's custom format string format
Browse files Browse the repository at this point in the history
  • Loading branch information
fmeum committed Jun 23, 2020
1 parent 6bfa0e7 commit 89c4317
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions app/src/main/java/com/zeapo/pwdstore/git/config/SshjConfig.kt
Original file line number Diff line number Diff line change
Expand Up @@ -158,24 +158,29 @@ object TimberLoggerFactory : LoggerFactory {
override fun isWarnEnabled() = true
override fun isErrorEnabled() = true

// Replace slf4j's "{}" format string style with standard Java's "%s".
// The supposedly redundant escape on the } is not redundant.
@Suppress("RegExpRedundantEscape")
private fun String.fix() = replace("""(?!<\\)\{\}""".toRegex(), "%s")

override fun t(message: String, t: Throwable?, vararg args: Any?) {
Timber.tag(name).v(t, message, *args)
Timber.tag(name).v(t, message.fix(), *args)
}

override fun d(message: String, t: Throwable?, vararg args: Any?) {
Timber.tag(name).d(t, message, *args)
Timber.tag(name).d(t, message.fix(), *args)
}

override fun i(message: String, t: Throwable?, vararg args: Any?) {
Timber.tag(name).i(t, message, *args)
Timber.tag(name).i(t, message.fix(), *args)
}

override fun w(message: String, t: Throwable?, vararg args: Any?) {
Timber.tag(name).w(t, message, *args)
Timber.tag(name).w(t, message.fix(), *args)
}

override fun e(message: String, t: Throwable?, vararg args: Any?) {
Timber.tag(name).e(t, message, *args)
Timber.tag(name).e(t, message.fix(), *args)
}
}

Expand Down

0 comments on commit 89c4317

Please sign in to comment.