File tree Expand file tree Collapse file tree 1 file changed +7
-8
lines changed
src/nativeMain/kotlin/io/github/oshai/kotlinlogging/internal Expand file tree Collapse file tree 1 file changed +7
-8
lines changed Original file line number Diff line number Diff line change @@ -23,16 +23,15 @@ internal actual object KLoggerNameResolver {
23
23
// Fallback for top-level loggers: Parse the stack trace string array.
24
24
val stackTrace: Array <String > = Throwable ().getStackTrace()
25
25
26
- // Find the call to this function as a reliable anchor.
27
- val resolverCallIndex =
28
- stackTrace.indexOfFirst {
29
- it.contains(" io.github.oshai.kotlinlogging.internal.KLoggerNameResolver#name" )
26
+ // Find the first frame outside of the logging framework's internal machinery.
27
+ val callerFrame =
28
+ stackTrace.firstOrNull {
29
+ ! it.contains(" kfun:kotlin.Throwable" ) &&
30
+ ! it.contains(" io.github.oshai.kotlinlogging.internal" ) &&
31
+ ! it.contains(" io.github.oshai.kotlinlogging.KotlinLogging" )
30
32
}
31
33
32
- // The caller is two frames up from this function in the stack trace.
33
- val callerFrameIndex = resolverCallIndex + 2
34
- if (resolverCallIndex != - 1 && callerFrameIndex < stackTrace.size) {
35
- val callerFrame = stackTrace[callerFrameIndex]
34
+ if (callerFrame != null ) {
36
35
val regex = Regex (""" kfun:([^#(<]+)""" )
37
36
val fqName = regex.find(callerFrame)?.groupValues?.get(1 )?.trim()
38
37
if (fqName != null ) {
You can’t perform that action at this time.
0 commit comments