Skip to content

Commit

Permalink
allow only markers being supplied
Browse files Browse the repository at this point in the history
  • Loading branch information
ewoelfel authored and oshai committed Mar 24, 2024
1 parent 7459e5c commit 41dcc10
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/commonMain/kotlin/io/github/oshai/kotlinlogging/KLogger.kt
Original file line number Diff line number Diff line change
Expand Up @@ -74,35 +74,35 @@ public interface KLogger {
}

/** Lazy add a log message if isTraceEnabled is true */
public fun trace(throwable: Throwable?, marker: Marker?, message: () -> Any?): Unit =
public fun trace(throwable: Throwable? = null, marker: Marker?, message: () -> Any?): Unit =
at(Level.TRACE, marker) {
this.message = message.toStringSafe()
this.cause = throwable
}

/** Lazy add a log message if isDebugEnabled is true */
public fun debug(throwable: Throwable?, marker: Marker?, message: () -> Any?): Unit =
public fun debug(throwable: Throwable? = null, marker: Marker?, message: () -> Any?): Unit =
at(Level.DEBUG, marker) {
this.message = message.toStringSafe()
this.cause = throwable
}

/** Lazy add a log message if isInfoEnabled is true */
public fun info(throwable: Throwable?, marker: Marker?, message: () -> Any?): Unit =
public fun info(throwable: Throwable? = null, marker: Marker?, message: () -> Any?): Unit =
at(Level.INFO, marker) {
this.message = message.toStringSafe()
this.cause = throwable
}

/** Lazy add a log message if isWarnEnabled is true */
public fun warn(throwable: Throwable?, marker: Marker?, message: () -> Any?): Unit =
public fun warn(throwable: Throwable? = null, marker: Marker?, message: () -> Any?): Unit =
at(Level.WARN, marker) {
this.message = message.toStringSafe()
this.cause = throwable
}

/** Lazy add a log message if isErrorEnabled is true */
public fun error(throwable: Throwable?, marker: Marker?, message: () -> Any?): Unit =
public fun error(throwable: Throwable? = null, marker: Marker?, message: () -> Any?): Unit =
at(Level.ERROR, marker) {
this.message = message.toStringSafe()
this.cause = throwable
Expand Down
12 changes: 12 additions & 0 deletions src/commonTest/kotlin/io/github/oshai/kotlinlogging/SimpleTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,16 @@ class SimpleTest {
fun simpleTest() {
logger.info { "Hello!" }
}

@Test
fun shouldSupportMarkers() {

val marker = KMarkerFactory.getMarker("someMarker")

logger.info(marker = marker) { "info" }
logger.debug(marker = marker) { "debug" }
logger.error(marker = marker) { "error" }
logger.error(marker = marker) { "warn" }
logger.trace(marker = marker) { "trace" }
}
}

0 comments on commit 41dcc10

Please sign in to comment.