-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
imp: added a debug function to debug logging before logging is config…
…ured
- Loading branch information
Showing
2 changed files
with
49 additions
and
0 deletions.
There are no files selected for viewing
7 changes: 7 additions & 0 deletions
7
...s/logging/logging-configure/src/main/kotlin/io/tnboot/logging/configure/internal/Debug.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 |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package io.tnboot.logging.configure.internal | ||
|
||
internal fun debug(message: String) { | ||
if (System.getProperty("io.tnboot.debug")?.contains("logging") == true) { | ||
println("[DEBUG] (io.tnboot.logging) $message") | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
...gging/logging-configure/src/test/kotlin/io/tnboot/logging/configure/internal/DebugTest.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 |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package io.tnboot.logging.configure.internal | ||
|
||
import java.io.ByteArrayOutputStream | ||
import java.io.PrintStream | ||
import kotlin.test.Test | ||
import kotlin.test.assertEquals | ||
|
||
class DebugTest { | ||
@Test | ||
fun `should debug logging when logging is included in io-tnboot-logging`() = synchronized(this) { | ||
val previousOut = System.out | ||
val outputStream = ByteArrayOutputStream() | ||
System.setOut(PrintStream(outputStream)) | ||
|
||
val beforeProperty = System.getProperty("io.tnboot.debug") | ||
System.setProperty("io.tnboot.debug", "logging") | ||
|
||
debug("Hello, World!") | ||
|
||
System.setOut(previousOut) | ||
beforeProperty?.let { System.setProperty("io.tnboot.debug", it) } ?: System.clearProperty("io.tnboot.debug") | ||
|
||
assertEquals("[DEBUG] (io.tnboot.logging) Hello, World!\n", outputStream.toString()) | ||
} | ||
|
||
@Test | ||
fun `should not debug logging when logging is not included in io-tnboot-logging`() = synchronized(this) { | ||
val previousOut = System.out | ||
val outputStream = ByteArrayOutputStream() | ||
System.setOut(PrintStream(outputStream)) | ||
|
||
val beforeProperty = System.getProperty("io.tnboot.debug") | ||
System.setProperty("io.tnboot.debug", "something-else") | ||
|
||
debug("Hello, World!") | ||
|
||
System.setOut(previousOut) | ||
beforeProperty?.let { System.setProperty("io.tnboot.debug", it) } ?: System.clearProperty("io.tnboot.debug") | ||
|
||
assertEquals(0, outputStream.size()) | ||
} | ||
} |