You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@logging.apache.org by ma...@apache.org on 2018/03/27 17:55:39 UTC
[19/25] logging-log4j-kotlin git commit: Simplify traceEntry/traceExit
Simplify traceEntry/traceExit
Project: http://git-wip-us.apache.org/repos/asf/logging-log4j-kotlin/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j-kotlin/commit/e4243b9e
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j-kotlin/tree/e4243b9e
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j-kotlin/diff/e4243b9e
Branch: refs/heads/master
Commit: e4243b9eab12977eb254c01b90dd843853ff4cc0
Parents: db30ecb
Author: Raman Gupta <ro...@gmail.com>
Authored: Fri Mar 2 00:24:47 2018 -0500
Committer: Raman Gupta <ro...@gmail.com>
Committed: Fri Mar 2 00:26:03 2018 -0500
----------------------------------------------------------------------
.../apache/logging/log4j/kotlin/KotlinLogger.kt | 52 +++++---------------
1 file changed, 11 insertions(+), 41 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/logging-log4j-kotlin/blob/e4243b9e/log4j-api-kotlin/src/main/kotlin/org/apache/logging/log4j/kotlin/KotlinLogger.kt
----------------------------------------------------------------------
diff --git a/log4j-api-kotlin/src/main/kotlin/org/apache/logging/log4j/kotlin/KotlinLogger.kt b/log4j-api-kotlin/src/main/kotlin/org/apache/logging/log4j/kotlin/KotlinLogger.kt
index eff1497..2b74b61 100644
--- a/log4j-api-kotlin/src/main/kotlin/org/apache/logging/log4j/kotlin/KotlinLogger.kt
+++ b/log4j-api-kotlin/src/main/kotlin/org/apache/logging/log4j/kotlin/KotlinLogger.kt
@@ -21,6 +21,7 @@ import org.apache.logging.log4j.Logger
import org.apache.logging.log4j.Marker
import org.apache.logging.log4j.message.EntryMessage
import org.apache.logging.log4j.message.Message
+import org.apache.logging.log4j.message.SimpleMessage
import org.apache.logging.log4j.spi.ExtendedLogger
/**
@@ -195,23 +196,21 @@ class KotlinLogger(val delegate: ExtendedLogger) {
}
// TODO entry with fqcn is not part of the ExtendedLogger interface, location-awareness will be broken
- // TODO kotlin-ize these
- fun traceEntry(): EntryMessage {
- return delegate.traceEntry()
+ fun traceEntry(msg: CharSequence): EntryMessage {
+ return delegate.traceEntry(SimpleMessage(msg))
}
// TODO entry with fqcn is not part of the ExtendedLogger interface, location-awareness will be broken
- fun traceEntry(format: String?, vararg params: Any?): EntryMessage {
- return delegate.traceEntry(format, *params)
+ fun traceEntry(supplier: () -> CharSequence): EntryMessage? {
+ return if(delegate.isTraceEnabled) delegate.traceEntry(SimpleMessage(supplier())) else null
}
fun traceEntry(vararg paramSuppliers: () -> Any?): EntryMessage {
return delegate.traceEntry(*paramSuppliers.asLog4jSuppliers())
}
- // TODO entry with fqcn is not part of the ExtendedLogger interface, location-awareness will be broken
- fun traceEntry(format: String?, vararg paramSuppliers: () -> Any?): EntryMessage {
- return delegate.traceEntry(format, *paramSuppliers.asLog4jSuppliers())
+ fun traceEntry(vararg params: Any?): EntryMessage {
+ return delegate.traceEntry(null, params)
}
// TODO entry with fqcn is not part of the ExtendedLogger interface, location-awareness will be broken
@@ -219,46 +218,17 @@ class KotlinLogger(val delegate: ExtendedLogger) {
return delegate.traceEntry(message)
}
- // TODO exit with fqcn is not part of the ExtendedLogger interface, location-awareness will be broken
- fun traceExit() {
- delegate.traceExit()
- }
-
- // TODO exit with fqcn is not part of the ExtendedLogger interface, location-awareness will be broken
- fun <R : Any?> traceExit(format: String?, result: R): R {
- return delegate.traceExit(format, result)
- }
-
- // TODO exit with fqcn is not part of the ExtendedLogger interface, location-awareness will be broken
- fun <R : Any?> traceExit(message: Message, result: R): R {
- return delegate.traceExit(message, result)
- }
-
- // TODO exit with fqcn is not part of the ExtendedLogger interface, location-awareness will be broken
- fun traceExit(message: EntryMessage) {
- delegate.traceExit(message)
- }
-
- // TODO exit with fqcn is not part of the ExtendedLogger interface, location-awareness will be broken
- fun <R : Any?> traceExit(result: R): R {
- return delegate.traceExit(result)
- }
-
- // TODO exit with fqcn is not part of the ExtendedLogger interface, location-awareness will be broken
- fun <R : Any?> traceExit(message: EntryMessage, result: R): R {
- return delegate.traceExit(message, result)
- }
-
fun <R : Any?> runInTrace(block: () -> R): R {
- return runInTrace(traceEntry(), block)
+ return runInTrace(delegate.traceEntry(), block)
}
+ // TODO exit and catching with fqcn is not part of the ExtendedLogger interface, location-awareness will be broken
fun <R : Any?> runInTrace(entryMessage: EntryMessage, block: () -> R): R {
return try {
val result = block()
when(result) {
- Unit -> traceExit(entryMessage)
- else -> traceExit(entryMessage, result)
+ Unit -> delegate.traceExit(entryMessage)
+ else -> delegate.traceExit(entryMessage, result)
}
result
} catch (e: Throwable) {