File tree Expand file tree Collapse file tree 2 files changed +43
-1
lines changed Expand file tree Collapse file tree 2 files changed +43
-1
lines changed Original file line number Diff line number Diff line change @@ -43,4 +43,39 @@ class KLogger(jLogger: Logger): Logger by jLogger{
43
43
inline fun error (msg : () -> Any? ) {
44
44
if (isErrorEnabled) error(msg.invoke().toString())
45
45
}
46
+
47
+ /* *
48
+ * Lazy add a log message with throwable payload if isTraceEnabled is true
49
+ */
50
+ inline fun trace (t : Throwable , msg : () -> Any? ) {
51
+ if (isTraceEnabled) trace(msg.invoke().toString(), t)
52
+ }
53
+
54
+ /* *
55
+ * Lazy add a log message with throwable payload if isDebugEnabled is true
56
+ */
57
+ inline fun debug (t : Throwable , msg : () -> Any? ) {
58
+ if (isDebugEnabled) debug(msg.invoke().toString(), t)
59
+ }
60
+
61
+ /* *
62
+ * Lazy add a log message with throwable payload if isInfoEnabled is true
63
+ */
64
+ inline fun info (t : Throwable , msg : () -> Any? ) {
65
+ if (isInfoEnabled) info(msg.invoke().toString(), t)
66
+ }
67
+
68
+ /* *
69
+ * Lazy add a log message with throwable payload if isWarnEnabled is true
70
+ */
71
+ inline fun warn (t : Throwable , msg : () -> Any? ) {
72
+ if (isWarnEnabled) warn(msg.invoke().toString(), t)
73
+ }
74
+
75
+ /* *
76
+ * Lazy add a log message with throwable payload if isErrorEnabled is true
77
+ */
78
+ inline fun error (t : Throwable , msg : () -> Any? ) {
79
+ if (isErrorEnabled) error(msg.invoke().toString(), t)
80
+ }
46
81
}
Original file line number Diff line number Diff line change @@ -8,6 +8,10 @@ class ClassWithLogging {
8
8
fun test () {
9
9
logger.info{" test ClassWithLogging" }
10
10
}
11
+ fun testThrowable () {
12
+ val ex = Throwable ()
13
+ logger.trace(ex){" test ChildClassWithLogging" }
14
+ }
11
15
}
12
16
open class ClassHasLogging : KLoggable {
13
17
override val logger = logger()
@@ -57,7 +61,10 @@ class LoggingTest {
57
61
58
62
@Test
59
63
fun testMessages () {
60
- ClassWithLogging ().test()
64
+ ClassWithLogging ().apply {
65
+ test()
66
+ testThrowable()
67
+ }
61
68
ClassInheritLogging ().test()
62
69
ChildClassWithLogging ().test()
63
70
ClassWithNamedLogging ().test()
You can’t perform that action at this time.
0 commit comments