aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/java
diff options
context:
space:
mode:
authorHarsh Shandilya <me@msfjarvis.dev>2023-01-28 18:57:48 +0530
committerHarsh Shandilya <me@msfjarvis.dev>2023-01-28 19:01:05 +0530
commit09bbd9ea82555416cab1d8d4c2ff54f9f1b904d7 (patch)
treec1f744eeb882584e983edbd4bf5c0185a5a3ea9b /app/src/main/java
parentca032a17373ae8e4e76f47cbc5963ac527b474d9 (diff)
feat: wire up SLF4J integration
Diffstat (limited to 'app/src/main/java')
-rw-r--r--app/src/main/java/app/passwordstore/util/log/LogcatLoggerFactory.kt17
-rw-r--r--app/src/main/java/org/slf4j/impl/StaticLoggerBinder.kt23
-rw-r--r--app/src/main/java/org/slf4j/impl/StaticMDCBinder.kt21
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()
+ }
+}