Skip to content

Commit

Permalink
Fix build failures after merge of oshai#119
Browse files Browse the repository at this point in the history
  • Loading branch information
Thad Cox committed Jul 16, 2020
1 parent 0225e78 commit efe15bc
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 7 deletions.
5 changes: 5 additions & 0 deletions src/linuxX64Main/kotlin/mu/KLogger.kt
Expand Up @@ -2,6 +2,11 @@ package mu

actual interface KLogger {

/**
* Logger Name
*/
actual val name: String

/**
* Lazy add a log message if isTraceEnabled is true
*/
Expand Down
9 changes: 9 additions & 0 deletions src/linuxX64Main/kotlin/mu/KLoggerFactory.kt
@@ -0,0 +1,9 @@
package mu

/**
* Factory for creating KLoggers
*/
actual interface KLoggerFactory {
actual fun logger(name: String): KLogger
actual fun logger(func: () -> Unit): KLogger
}
7 changes: 5 additions & 2 deletions src/linuxX64Main/kotlin/mu/KotlinLogging.kt
@@ -1,5 +1,6 @@
package mu

import mu.internal.KLoggerFactoryDefault
import mu.internal.KLoggerLinux


Expand All @@ -10,7 +11,9 @@ actual object KotlinLogging {
* val logger = KotlinLogging.logger {}
* ```
*/
actual fun logger(func: () -> Unit): KLogger = KLoggerLinux(func::class.qualifiedName ?: "")
actual fun logger(func: () -> Unit): KLogger = kLoggerFactory.logger(func)

actual fun logger(name: String): KLogger = KLoggerLinux(name)
actual fun logger(name: String): KLogger = kLoggerFactory.logger(name)

actual var kLoggerFactory: KLoggerFactory = KLoggerFactoryDefault
}
21 changes: 21 additions & 0 deletions src/linuxX64Main/kotlin/mu/internal/KLoggerFactoryDefault.kt
@@ -0,0 +1,21 @@
package mu.internal

import mu.KLogger
import mu.KLoggerFactory

/**
* factory methods to obtain a [KLogger]
*/
@Suppress("NOTHING_TO_INLINE")
internal actual object KLoggerFactoryDefault : KLoggerFactory {
/**
* get logger by explicit name
*/
actual override fun logger(name: String): KLogger = KLoggerLinux(name)

/**
* get logger for the method, assuming it was declared at the logger file/class
*/
actual override fun logger(func: () -> Unit): KLogger = logger(func::class.qualifiedName ?: "")

}
10 changes: 5 additions & 5 deletions src/linuxX64Main/kotlin/mu/internal/KLoggerLinux.kt
Expand Up @@ -13,7 +13,7 @@ import mu.Marker
import mu.isLoggingEnabled

internal class KLoggerLinux(
private val loggerName: String
override val name: String
) : KLogger {

override fun trace(msg: () -> Any?) = TRACE.logIfEnabled(msg, appender::trace)
Expand Down Expand Up @@ -63,19 +63,19 @@ internal class KLoggerLinux(

private fun KotlinLoggingLevel.logIfEnabled(msg: () -> Any?, logFunction: (Any?) -> Unit) {
if (isLoggingEnabled()) {
logFunction(formatter.formatMessage(this, loggerName, msg))
logFunction(formatter.formatMessage(this, name, msg))
}
}

private fun KotlinLoggingLevel.logIfEnabled(msg: () -> Any?, t: Throwable?, logFunction: (Any?) -> Unit) {
if (isLoggingEnabled()) {
logFunction(formatter.formatMessage(this, loggerName, t, msg))
logFunction(formatter.formatMessage(this, name, t, msg))
}
}

private fun KotlinLoggingLevel.logIfEnabled(marker: Marker?, msg: () -> Any?, logFunction: (Any?) -> Unit) {
if (isLoggingEnabled()) {
logFunction(formatter.formatMessage(this, loggerName, marker, msg))
logFunction(formatter.formatMessage(this, name, marker, msg))
}
}

Expand All @@ -86,7 +86,7 @@ internal class KLoggerLinux(
logFunction: (Any?) -> Unit
) {
if (isLoggingEnabled()) {
logFunction(formatter.formatMessage(this, loggerName, marker, t, msg))
logFunction(formatter.formatMessage(this, name, marker, t, msg))
}
}

Expand Down

0 comments on commit efe15bc

Please sign in to comment.