-
-
Notifications
You must be signed in to change notification settings - Fork 112
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Populate caller information from compiler data, if available
- Loading branch information
Neeme Praks
committed
Oct 28, 2024
1 parent
797b15d
commit c7047dc
Showing
2 changed files
with
37 additions
and
12 deletions.
There are no files selected for viewing
42 changes: 35 additions & 7 deletions
42
src/jvmMain/kotlin/io/github/oshai/kotlinlogging/logback/internal/LogbackLogEvent.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,48 @@ | ||
package io.github.oshai.kotlinlogging.logback.internal | ||
|
||
import ch.qos.logback.classic.Level | ||
import ch.qos.logback.classic.Logger | ||
import ch.qos.logback.classic.spi.LoggingEvent | ||
import io.github.oshai.kotlinlogging.KLoggingEventBuilder | ||
import io.github.oshai.kotlinlogging.Level | ||
import io.github.oshai.kotlinlogging.logback.toLogbackLevel | ||
|
||
public class LogbackLogEvent( | ||
fqcn: String, | ||
logger: Logger, | ||
level: Level, | ||
message: String?, | ||
private val finalFormattedMessage: String?, | ||
throwable: Throwable?, | ||
argArray: Array<Any>, | ||
) : LoggingEvent(fqcn, logger, level, message, throwable, argArray) { | ||
private val kLoggingEvent: KLoggingEventBuilder, | ||
) : | ||
LoggingEvent( | ||
fqcn, | ||
logger, | ||
level.toLogbackLevel(), | ||
kLoggingEvent.internalCompilerData?.messageTemplate ?: kLoggingEvent.message, | ||
kLoggingEvent.cause, | ||
emptyArray(), | ||
) { | ||
|
||
override fun getFormattedMessage(): String? { | ||
return finalFormattedMessage | ||
return kLoggingEvent.message | ||
} | ||
|
||
override fun getCallerData(): Array<StackTraceElement> = | ||
if (kLoggingEvent.internalCompilerData?.fileName != null) { | ||
arrayOf( | ||
StackTraceElement( | ||
kLoggingEvent.internalCompilerData?.className, | ||
kLoggingEvent.internalCompilerData?.methodName, | ||
kLoggingEvent.internalCompilerData?.fileName, | ||
kLoggingEvent.internalCompilerData?.lineNumber ?: 0, | ||
) | ||
) | ||
} else { | ||
super.getCallerData() | ||
} | ||
|
||
override fun hasCallerData(): Boolean = | ||
if (kLoggingEvent.internalCompilerData?.fileName != null) { | ||
true | ||
} else { | ||
super.hasCallerData() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters