diff options
Diffstat (limited to 'app')
3 files changed, 61 insertions, 0 deletions
diff --git a/app/src/main/java/app/passwordstore/util/log/LogcatLoggerFactory.kt b/app/src/main/java/app/passwordstore/util/log/LogcatLoggerFactory.kt new file mode 100644 index 00000000..92464446 --- /dev/null +++ b/app/src/main/java/app/passwordstore/util/log/LogcatLoggerFactory.kt @@ -0,0 +1,17 @@ +package app.passwordstore.util.log + +import java.util.concurrent.ConcurrentHashMap +import org.slf4j.ILoggerFactory +import org.slf4j.Logger + +/** + * [ILoggerFactory] implementation that passes out instances of [LogcatLogger], maintaining an + * internal cache of [Logger]s to avoid duplicate initialization. + */ +class LogcatLoggerFactory : ILoggerFactory { + + private val loggers = ConcurrentHashMap<String, Logger>() + override fun getLogger(name: String): Logger { + return loggers.getOrPut(name) { LogcatLogger(name) } + } +} diff --git a/app/src/main/java/org/slf4j/impl/StaticLoggerBinder.kt b/app/src/main/java/org/slf4j/impl/StaticLoggerBinder.kt new file mode 100644 index 00000000..85ab4d42 --- /dev/null +++ b/app/src/main/java/org/slf4j/impl/StaticLoggerBinder.kt @@ -0,0 +1,23 @@ +@file:Suppress("Unused") + +package org.slf4j.impl + +import app.passwordstore.util.log.LogcatLoggerFactory +import org.slf4j.ILoggerFactory +import org.slf4j.spi.LoggerFactoryBinder + +class StaticLoggerBinder : LoggerFactoryBinder { + private val loggerFactory: ILoggerFactory = LogcatLoggerFactory() + private val loggerFactoryClassStr = LogcatLoggerFactory::javaClass.name + + override fun getLoggerFactory(): ILoggerFactory { + return loggerFactory + } + override fun getLoggerFactoryClassStr(): String { + return loggerFactoryClassStr + } + + companion object { + @JvmStatic val singleton = StaticLoggerBinder() + } +} diff --git a/app/src/main/java/org/slf4j/impl/StaticMDCBinder.kt b/app/src/main/java/org/slf4j/impl/StaticMDCBinder.kt new file mode 100644 index 00000000..d75c8ed0 --- /dev/null +++ b/app/src/main/java/org/slf4j/impl/StaticMDCBinder.kt @@ -0,0 +1,21 @@ +@file:Suppress("Unused") + +package org.slf4j.impl + +import org.slf4j.helpers.BasicMDCAdapter +import org.slf4j.spi.MDCAdapter + +class StaticMDCBinder { + + fun getMDCA(): MDCAdapter { + return BasicMDCAdapter() + } + + fun getMDCAdapterClassStr(): String? { + return BasicMDCAdapter::class.java.name + } + + companion object { + @JvmStatic val singleton = StaticMDCBinder() + } +} |