Skip to content

Commit

Permalink
Add default empty message parameters
Browse files Browse the repository at this point in the history
Useful in case you only want to log the class and function but have
no specific message, e.g.:

```kotlin
class Foo {
    fun bar() {
        Log.debug()
    }
}
```

Will output only
  • Loading branch information
saschpe committed Mar 23, 2024
1 parent fd300de commit cf8bca3
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 6 deletions.
12 changes: 6 additions & 6 deletions log4k/src/commonMain/kotlin/saschpe/log4k/Log.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ object Log {

@JvmOverloads
@JvmStatic
fun verbose(message: String, throwable: Throwable? = null, tag: String = "") =
fun verbose(message: String = "", throwable: Throwable? = null, tag: String = "") =
log(Level.Verbose, tag, throwable, message)

@JvmOverloads
Expand All @@ -32,7 +32,7 @@ object Log {

@JvmOverloads
@JvmStatic
fun info(message: String, throwable: Throwable? = null, tag: String = "") =
fun info(message: String = "", throwable: Throwable? = null, tag: String = "") =
log(Level.Info, tag, throwable, message)

@JvmOverloads
Expand All @@ -42,7 +42,7 @@ object Log {

@JvmOverloads
@JvmStatic
fun debug(message: String, throwable: Throwable? = null, tag: String = "") =
fun debug(message: String = "", throwable: Throwable? = null, tag: String = "") =
log(Level.Debug, tag, throwable, message)

@JvmOverloads
Expand All @@ -52,7 +52,7 @@ object Log {

@JvmOverloads
@JvmStatic
fun warn(message: String, throwable: Throwable? = null, tag: String = "") =
fun warn(message: String = "", throwable: Throwable? = null, tag: String = "") =
log(Level.Warning, tag, throwable, message)

@JvmOverloads
Expand All @@ -62,7 +62,7 @@ object Log {

@JvmOverloads
@JvmStatic
fun error(message: String, throwable: Throwable? = null, tag: String = "") =
fun error(message: String = "", throwable: Throwable? = null, tag: String = "") =
log(Level.Error, tag, throwable, message)

@JvmOverloads
Expand All @@ -72,7 +72,7 @@ object Log {

@JvmOverloads
@JvmStatic
fun assert(message: String, throwable: Throwable? = null, tag: String = "") =
fun assert(message: String = "", throwable: Throwable? = null, tag: String = "") =
log(Level.Assert, tag, throwable, message)

@JvmOverloads
Expand Down
54 changes: 54 additions & 0 deletions log4k/src/commonTest/kotlin/saschpe/log4k/LogTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,15 @@ class LogTest {
assertTestLogger(Log.Level.Verbose)
}

@Test
fun verbose_defaults() {
// Act
Log.verbose()

// Assert
assertTestLogger(Log.Level.Verbose, "", "", null)
}

@Test
fun verbose_withLambda() {
// Act
Expand All @@ -37,6 +46,15 @@ class LogTest {
assertTestLogger(Log.Level.Info)
}

@Test
fun info_defaults() {
// Act
Log.info()

// Assert
assertTestLogger(Log.Level.Info, "", "", null)
}

@Test
fun info_withLambda() {
// Act
Expand All @@ -55,6 +73,15 @@ class LogTest {
assertTestLogger(Log.Level.Debug)
}

@Test
fun debug_defaults() {
// Act
Log.debug()

// Assert
assertTestLogger(Log.Level.Debug, "", "", null)
}

@Test
fun debug_withLambda() {
// Act
Expand All @@ -73,6 +100,15 @@ class LogTest {
assertTestLogger(Log.Level.Warning)
}

@Test
fun warn_defaults() {
// Act
Log.warn()

// Assert
assertTestLogger(Log.Level.Warning, "", "", null)
}

@Test
fun warn_withLambda() {
// Act
Expand All @@ -91,6 +127,15 @@ class LogTest {
assertTestLogger(Log.Level.Error)
}

@Test
fun error_defaults() {
// Act
Log.error()

// Assert
assertTestLogger(Log.Level.Error, "", "", null)
}

@Test
fun error_withLambda() {
// Act
Expand All @@ -109,6 +154,15 @@ class LogTest {
assertTestLogger(Log.Level.Assert)
}

@Test
fun assert_defaults() {
// Act
Log.assert()

// Assert
assertTestLogger(Log.Level.Assert, "", "", null)
}

@Test
fun assert_withLambda() {
// Act
Expand Down

0 comments on commit cf8bca3

Please sign in to comment.