feat: wire up SLF4J integration

This commit is contained in:
Harsh Shandilya 2023-01-28 18:57:48 +05:30
parent ca032a1737
commit 09bbd9ea82
No known key found for this signature in database
3 changed files with 61 additions and 0 deletions

View file

@ -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) }
}
}

View 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()
}
}

View 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()
}
}