Skip to content

Commit

Permalink
Add loggerName to the Appender interface
Browse files Browse the repository at this point in the history
On Darwin platforms using os_log, a separate logger can be created for
each differently named logger. The Appender, which directs the text of
the log message, needs to know which logger to direct it to.
  • Loading branch information
conradev authored and oshai committed May 20, 2022
1 parent 8d50673 commit 2ea0674
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 22 deletions.
10 changes: 5 additions & 5 deletions src/nativeMain/kotlin/mu/Appender.kt
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package mu

public interface Appender {
public fun trace(message: Any?)
public fun debug(message: Any?)
public fun info(message: Any?)
public fun warn(message: Any?)
public fun error(message: Any?)
public fun trace(loggerName: String, message: String)
public fun debug(loggerName: String, message: String)
public fun info(loggerName: String, message: String)
public fun warn(loggerName: String, message: String)
public fun error(loggerName: String, message: String)
}
10 changes: 5 additions & 5 deletions src/nativeMain/kotlin/mu/ConsoleOutputAppender.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ import platform.posix.fprintf
import platform.posix.stderr

public object ConsoleOutputAppender : Appender {
public override fun trace(message: Any?): Unit = println(message)
public override fun debug(message: Any?): Unit = println(message)
public override fun info(message: Any?): Unit = println(message)
public override fun warn(message: Any?): Unit = println(message)
public override fun trace(loggerName: String, message: String): Unit = println(message)
public override fun debug(loggerName: String, message: String): Unit = println(message)
public override fun info(loggerName: String, message: String): Unit = println(message)
public override fun warn(loggerName: String, message: String): Unit = println(message)

override fun error(message: Any?) {
override fun error(loggerName: String, message: String) {
fprintf(stderr, "$message\n")
}
}
8 changes: 4 additions & 4 deletions src/nativeMain/kotlin/mu/Formatter.kt
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package mu

public interface Formatter {
public fun formatMessage(level: KotlinLoggingLevel, loggerName: String, msg: () -> Any?): Any?
public fun formatMessage(level: KotlinLoggingLevel, loggerName: String, t: Throwable?, msg: () -> Any?): Any?
public fun formatMessage(level: KotlinLoggingLevel, loggerName: String, marker: Marker?, msg: () -> Any?): Any?
public fun formatMessage(level: KotlinLoggingLevel, loggerName: String, msg: () -> Any?): String
public fun formatMessage(level: KotlinLoggingLevel, loggerName: String, t: Throwable?, msg: () -> Any?): String
public fun formatMessage(level: KotlinLoggingLevel, loggerName: String, marker: Marker?, msg: () -> Any?): String
public fun formatMessage(
level: KotlinLoggingLevel,
loggerName: String,
marker: Marker?,
t: Throwable?,
msg: () -> Any?
): Any?
): String
}
16 changes: 8 additions & 8 deletions src/nativeMain/kotlin/mu/internal/KLoggerLinux.kt
Original file line number Diff line number Diff line change
Expand Up @@ -57,32 +57,32 @@ internal class KLoggerLinux(
override fun error(marker: Marker?, t: Throwable?, msg: () -> Any?) =
ERROR.logIfEnabled(marker, msg, t, appender::error)

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

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

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

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

Expand Down

0 comments on commit 2ea0674

Please sign in to comment.