feat: wire up SLF4J integration
This commit is contained in:
parent
ca032a1737
commit
09bbd9ea82
3 changed files with 61 additions and 0 deletions
|
@ -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) }
|
||||
}
|
||||
}
|
23
app/src/main/java/org/slf4j/impl/StaticLoggerBinder.kt
Normal file
23
app/src/main/java/org/slf4j/impl/StaticLoggerBinder.kt
Normal file
|
@ -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()
|
||||
}
|
||||
}
|
21
app/src/main/java/org/slf4j/impl/StaticMDCBinder.kt
Normal file
21
app/src/main/java/org/slf4j/impl/StaticMDCBinder.kt
Normal file
|
@ -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()
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue