-
-
Notifications
You must be signed in to change notification settings - Fork 116
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix #160 - throw error instead of show in log
in case system property is defined: kotlin-logging.throwOnMessageError
- Loading branch information
Showing
5 changed files
with
54 additions
and
1 deletion.
There are no files selected for viewing
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
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,5 @@ | ||
package mu.internal | ||
|
||
public actual object ErrorMessageProducer { | ||
public actual fun getErrorLog(e: Exception): String = "Log message invocation failed: $e" | ||
} |
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,12 @@ | ||
package mu.internal | ||
|
||
public actual object ErrorMessageProducer { | ||
public actual fun getErrorLog(e: Exception): String { | ||
if (System.getProperties().containsKey("kotlin-logging.throwOnMessageError")) { | ||
throw e | ||
} else { | ||
return "Log message invocation failed: $e" | ||
} | ||
} | ||
|
||
} |
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,27 @@ | ||
package mu.internal | ||
|
||
import org.junit.Test | ||
import kotlin.test.assertEquals | ||
|
||
class MessageInvokerJavaTest { | ||
|
||
@Test | ||
fun toStringSafeChecks() { | ||
assertEquals("hi", { "hi" }.toStringSafe()) | ||
} | ||
|
||
@Test | ||
fun toStringSafeChecksThrowException() { | ||
assertEquals("Log message invocation failed: java.lang.Exception: hi", { throw Exception("hi") }.toStringSafe()) | ||
} | ||
|
||
@Test(expected = Exception::class) | ||
fun toStringSafeChecksThrowExceptionWithSystemProperty() { | ||
System.setProperty("kotlin-logging.throwOnMessageError", "") | ||
try { | ||
{ throw Exception("hi") }.toStringSafe() | ||
} finally { | ||
System.clearProperty("kotlin-logging.throwOnMessageError") | ||
} | ||
} | ||
} |
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,5 @@ | ||
package mu.internal | ||
|
||
public actual object ErrorMessageProducer { | ||
public actual fun getErrorLog(e: Exception): String = "Log message invocation failed: $e" | ||
} |