Skip to content

Commit

Permalink
Logging: Remove kotlin-reflect usage
Browse files Browse the repository at this point in the history
  • Loading branch information
Juuxel committed Jan 15, 2024
1 parent 0d3b14a commit 6d78bd4
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions common/src/main/kotlin/juuxel/adorn/util/Logging.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,20 @@ private val STACK_WALKER = StackWalker.getInstance(StackWalker.Option.RETAIN_CLA
/**
* Gets a logger for the calling class.
*
* If called from a companion object, returns a logger
* for the enclosing class.
* If called from a nested class, returns a logger
* for the outermost class in the nest.
*
* If called from a top-level property initialiser,
* returns a logger for the enclosing file.
*/
fun logger(): Logger {
@Suppress("UsePropertyAccessSyntax") // not a pure property
var caller = STACK_WALKER.getCallerClass()
val enclosing = caller.enclosingClass

if (enclosing != null && caller.kotlin.isCompanion) {
caller = enclosing
// Locate the outermost class.
var next = caller.enclosingClass
while (next != null) {
caller = next
next = caller.enclosingClass
}

return LoggerFactory.getLogger(caller)
Expand Down

0 comments on commit 6d78bd4

Please sign in to comment.