Skip to content

Commit

Permalink
Merge pull request #6 from Prototik/slf4j2
Browse files Browse the repository at this point in the history
Add discovery of SLF4J 2.0+
  • Loading branch information
Romain Boisselle authored Jun 27, 2022
2 parents fcfbff4 + 8e7d2ba commit bee46c7
Showing 1 changed file with 19 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -1,14 +1,26 @@
package org.kodein.log.frontend

import org.kodein.log.LogFrontend
import java.util.ServiceLoader

private fun isSlf4jAvailable(): Boolean =
try {
Class.forName("org.slf4j.impl.StaticLoggerBinder")
true
} catch (_: ClassNotFoundException) {
false
}
private fun isSlf4jAvailable(): Boolean {
// SLF4J 1.0 - 1.7
try {
Class.forName("org.slf4j.impl.StaticLoggerBinder")
return true
} catch (_: ClassNotFoundException) {
}

// SLF4J 2.0+
try {
val slf4jSpi = Class.forName("org.slf4j.spi.SLF4JServiceProvider")
val loader = ServiceLoader.load(slf4jSpi)
return loader.any()
} catch (_: ClassNotFoundException) {
}

return false
}

private fun isAndroidAvailable(): Boolean =
try {
Expand Down

0 comments on commit bee46c7

Please sign in to comment.