diff --git a/core/src/main/kotlin/net/corda/core/utilities/KotlinUtils.kt b/core/src/main/kotlin/net/corda/core/utilities/KotlinUtils.kt new file mode 100644 index 0000000000..e6e656a199 --- /dev/null +++ b/core/src/main/kotlin/net/corda/core/utilities/KotlinUtils.kt @@ -0,0 +1,21 @@ +package net.corda.core.utilities + +import org.slf4j.Logger +import org.slf4j.LoggerFactory + +/** + * Get the [Logger] for a class using the syntax + * + * `val logger = loggerFor()` + */ +inline fun loggerFor(): Logger = LoggerFactory.getLogger(T::class.java) + +/** Log a TRACE level message produced by evaluating the given lamdba, but only if TRACE logging is enabled. */ +inline fun Logger.trace(msg: () -> String) { + if (isTraceEnabled) trace(msg()) +} + +/** Log a DEBUG level message produced by evaluating the given lamdba, but only if DEBUG logging is enabled. */ +inline fun Logger.debug(msg: () -> String) { + if (isDebugEnabled) debug(msg()) +} \ No newline at end of file diff --git a/finance/src/test/kotlin/net/corda/contracts/asset/CashTests.kt b/finance/src/test/kotlin/net/corda/contracts/asset/CashTests.kt index c27a2b4856..d08d9e36c4 100644 --- a/finance/src/test/kotlin/net/corda/contracts/asset/CashTests.kt +++ b/finance/src/test/kotlin/net/corda/contracts/asset/CashTests.kt @@ -13,7 +13,6 @@ import net.corda.core.node.services.unconsumedStates import net.corda.core.utilities.OpaqueBytes import net.corda.core.transactions.SignedTransaction import net.corda.core.transactions.WireTransaction -import net.corda.core.utilities.* import net.corda.node.services.vault.NodeVaultService import net.corda.node.utilities.configureDatabase import net.corda.node.utilities.transaction diff --git a/node/src/test/kotlin/net/corda/node/messaging/TwoPartyTradeFlowTests.kt b/node/src/test/kotlin/net/corda/node/messaging/TwoPartyTradeFlowTests.kt index 8e4e9611ba..d50a09fcd3 100644 --- a/node/src/test/kotlin/net/corda/node/messaging/TwoPartyTradeFlowTests.kt +++ b/node/src/test/kotlin/net/corda/node/messaging/TwoPartyTradeFlowTests.kt @@ -26,7 +26,7 @@ import net.corda.core.serialization.serialize import net.corda.core.transactions.SignedTransaction import net.corda.core.transactions.TransactionBuilder import net.corda.core.transactions.WireTransaction -import net.corda.core.utilities.LogHelper +import net.corda.testing.LogHelper import net.corda.core.utilities.unwrap import net.corda.flows.TwoPartyTradeFlow.Buyer import net.corda.flows.TwoPartyTradeFlow.Seller diff --git a/node/src/test/kotlin/net/corda/node/services/messaging/ArtemisMessagingTests.kt b/node/src/test/kotlin/net/corda/node/services/messaging/ArtemisMessagingTests.kt index 4a4a0cc7e3..b93802356b 100644 --- a/node/src/test/kotlin/net/corda/node/services/messaging/ArtemisMessagingTests.kt +++ b/node/src/test/kotlin/net/corda/node/services/messaging/ArtemisMessagingTests.kt @@ -8,7 +8,7 @@ import com.google.common.util.concurrent.SettableFuture import net.corda.core.crypto.generateKeyPair import net.corda.core.messaging.RPCOps import net.corda.core.node.services.DEFAULT_SESSION_ID -import net.corda.core.utilities.LogHelper +import net.corda.testing.LogHelper import net.corda.node.services.RPCUserService import net.corda.node.services.RPCUserServiceImpl import net.corda.node.services.api.MonitoringService diff --git a/node/src/test/kotlin/net/corda/node/services/persistence/DBCheckpointStorageTests.kt b/node/src/test/kotlin/net/corda/node/services/persistence/DBCheckpointStorageTests.kt index 095f20f9cb..92180fde67 100644 --- a/node/src/test/kotlin/net/corda/node/services/persistence/DBCheckpointStorageTests.kt +++ b/node/src/test/kotlin/net/corda/node/services/persistence/DBCheckpointStorageTests.kt @@ -2,7 +2,7 @@ package net.corda.node.services.persistence import com.google.common.primitives.Ints import net.corda.core.serialization.SerializedBytes -import net.corda.core.utilities.LogHelper +import net.corda.testing.LogHelper import net.corda.node.services.api.Checkpoint import net.corda.node.services.api.CheckpointStorage import net.corda.node.services.transactions.PersistentUniquenessProvider diff --git a/node/src/test/kotlin/net/corda/node/services/persistence/DBTransactionStorageTests.kt b/node/src/test/kotlin/net/corda/node/services/persistence/DBTransactionStorageTests.kt index fe4acd24b6..c98f62dfa3 100644 --- a/node/src/test/kotlin/net/corda/node/services/persistence/DBTransactionStorageTests.kt +++ b/node/src/test/kotlin/net/corda/node/services/persistence/DBTransactionStorageTests.kt @@ -9,7 +9,7 @@ import net.corda.core.toFuture import net.corda.core.transactions.SignedTransaction import net.corda.core.transactions.WireTransaction import net.corda.testing.DUMMY_NOTARY -import net.corda.core.utilities.LogHelper +import net.corda.testing.LogHelper import net.corda.node.services.transactions.PersistentUniquenessProvider import net.corda.node.utilities.configureDatabase import net.corda.node.utilities.transaction diff --git a/node/src/test/kotlin/net/corda/node/services/persistence/NodeAttachmentStorageTest.kt b/node/src/test/kotlin/net/corda/node/services/persistence/NodeAttachmentStorageTest.kt index 0246f69f64..f50738f6c3 100644 --- a/node/src/test/kotlin/net/corda/node/services/persistence/NodeAttachmentStorageTest.kt +++ b/node/src/test/kotlin/net/corda/node/services/persistence/NodeAttachmentStorageTest.kt @@ -7,7 +7,7 @@ import net.corda.core.crypto.SecureHash import net.corda.core.crypto.sha256 import net.corda.core.read import net.corda.core.readAll -import net.corda.core.utilities.LogHelper +import net.corda.testing.LogHelper import net.corda.core.write import net.corda.core.writeLines import net.corda.node.services.database.RequeryConfiguration diff --git a/node/src/test/kotlin/net/corda/node/services/schema/HibernateObserverTests.kt b/node/src/test/kotlin/net/corda/node/services/schema/HibernateObserverTests.kt index 8c087f2b1c..6cb9b6c47c 100644 --- a/node/src/test/kotlin/net/corda/node/services/schema/HibernateObserverTests.kt +++ b/node/src/test/kotlin/net/corda/node/services/schema/HibernateObserverTests.kt @@ -1,17 +1,15 @@ package net.corda.node.services.schema import net.corda.core.contracts.* -import net.corda.core.crypto.CompositeKey import net.corda.core.crypto.SecureHash import net.corda.core.identity.AbstractParty import net.corda.core.node.services.Vault import net.corda.core.schemas.MappedSchema import net.corda.core.schemas.PersistentState import net.corda.core.schemas.QueryableState -import net.corda.core.utilities.LogHelper +import net.corda.testing.LogHelper import net.corda.node.services.api.SchemaService import net.corda.node.services.database.HibernateConfiguration -import net.corda.node.services.schema.HibernateObserver import net.corda.node.utilities.configureDatabase import net.corda.node.utilities.transaction import net.corda.testing.MEGA_CORP diff --git a/node/src/test/kotlin/net/corda/node/services/statemachine/FlowFrameworkTests.kt b/node/src/test/kotlin/net/corda/node/services/statemachine/FlowFrameworkTests.kt index 9773a7f733..e59e703dec 100644 --- a/node/src/test/kotlin/net/corda/node/services/statemachine/FlowFrameworkTests.kt +++ b/node/src/test/kotlin/net/corda/node/services/statemachine/FlowFrameworkTests.kt @@ -25,7 +25,7 @@ import net.corda.core.utilities.OpaqueBytes import net.corda.core.serialization.deserialize import net.corda.core.transactions.SignedTransaction import net.corda.core.transactions.TransactionBuilder -import net.corda.core.utilities.LogHelper +import net.corda.testing.LogHelper import net.corda.core.utilities.ProgressTracker import net.corda.core.utilities.ProgressTracker.Change import net.corda.core.utilities.unwrap diff --git a/node/src/test/kotlin/net/corda/node/services/transactions/DistributedImmutableMapTests.kt b/node/src/test/kotlin/net/corda/node/services/transactions/DistributedImmutableMapTests.kt index 3500211147..fe57ded32c 100644 --- a/node/src/test/kotlin/net/corda/node/services/transactions/DistributedImmutableMapTests.kt +++ b/node/src/test/kotlin/net/corda/node/services/transactions/DistributedImmutableMapTests.kt @@ -8,9 +8,8 @@ import io.atomix.copycat.server.CopycatServer import io.atomix.copycat.server.storage.Storage import io.atomix.copycat.server.storage.StorageLevel import net.corda.core.getOrThrow -import net.corda.core.utilities.LogHelper +import net.corda.testing.LogHelper import net.corda.node.services.network.NetworkMapService -import net.corda.node.services.transactions.DistributedImmutableMap import net.corda.node.utilities.configureDatabase import net.corda.testing.freeLocalHostAndPort import net.corda.testing.node.makeTestDataSourceProperties diff --git a/node/src/test/kotlin/net/corda/node/services/transactions/PersistentUniquenessProviderTests.kt b/node/src/test/kotlin/net/corda/node/services/transactions/PersistentUniquenessProviderTests.kt index 4f14caa074..1ff8c103f3 100644 --- a/node/src/test/kotlin/net/corda/node/services/transactions/PersistentUniquenessProviderTests.kt +++ b/node/src/test/kotlin/net/corda/node/services/transactions/PersistentUniquenessProviderTests.kt @@ -2,8 +2,7 @@ package net.corda.node.services.transactions import net.corda.core.crypto.SecureHash import net.corda.core.node.services.UniquenessException -import net.corda.core.utilities.LogHelper -import net.corda.node.services.transactions.PersistentUniquenessProvider +import net.corda.testing.LogHelper import net.corda.node.utilities.configureDatabase import net.corda.node.utilities.transaction import net.corda.testing.MEGA_CORP diff --git a/node/src/test/kotlin/net/corda/node/services/vault/NodeVaultServiceTest.kt b/node/src/test/kotlin/net/corda/node/services/vault/NodeVaultServiceTest.kt index 8ce32149e0..1f52670c79 100644 --- a/node/src/test/kotlin/net/corda/node/services/vault/NodeVaultServiceTest.kt +++ b/node/src/test/kotlin/net/corda/node/services/vault/NodeVaultServiceTest.kt @@ -11,7 +11,7 @@ import net.corda.core.node.services.unconsumedStates import net.corda.core.utilities.OpaqueBytes import net.corda.core.transactions.SignedTransaction import net.corda.testing.DUMMY_NOTARY -import net.corda.core.utilities.LogHelper +import net.corda.testing.LogHelper import net.corda.node.utilities.configureDatabase import net.corda.node.utilities.transaction import net.corda.testing.BOC diff --git a/node/src/test/kotlin/net/corda/node/services/vault/VaultWithCashTest.kt b/node/src/test/kotlin/net/corda/node/services/vault/VaultWithCashTest.kt index 1c3de0094f..50314208d4 100644 --- a/node/src/test/kotlin/net/corda/node/services/vault/VaultWithCashTest.kt +++ b/node/src/test/kotlin/net/corda/node/services/vault/VaultWithCashTest.kt @@ -16,7 +16,7 @@ import net.corda.core.transactions.SignedTransaction import net.corda.testing.BOB import net.corda.testing.DUMMY_NOTARY import net.corda.testing.DUMMY_NOTARY_KEY -import net.corda.core.utilities.LogHelper +import net.corda.testing.LogHelper import net.corda.node.utilities.configureDatabase import net.corda.node.utilities.transaction import net.corda.testing.MEGA_CORP diff --git a/samples/irs-demo/src/test/kotlin/net/corda/irs/api/NodeInterestRatesTest.kt b/samples/irs-demo/src/test/kotlin/net/corda/irs/api/NodeInterestRatesTest.kt index d9113124ae..9d3035cef3 100644 --- a/samples/irs-demo/src/test/kotlin/net/corda/irs/api/NodeInterestRatesTest.kt +++ b/samples/irs-demo/src/test/kotlin/net/corda/irs/api/NodeInterestRatesTest.kt @@ -14,7 +14,7 @@ import net.corda.core.getOrThrow import net.corda.core.identity.Party import net.corda.core.node.services.ServiceInfo import net.corda.core.transactions.TransactionBuilder -import net.corda.core.utilities.LogHelper +import net.corda.testing.LogHelper import net.corda.core.utilities.ProgressTracker import net.corda.irs.flows.RatesFixFlow import net.corda.node.utilities.configureDatabase diff --git a/samples/network-visualiser/src/test/kotlin/net/corda/netmap/simulation/IRSSimulationTest.kt b/samples/network-visualiser/src/test/kotlin/net/corda/netmap/simulation/IRSSimulationTest.kt index 97777c9dbe..6fc24d24e3 100644 --- a/samples/network-visualiser/src/test/kotlin/net/corda/netmap/simulation/IRSSimulationTest.kt +++ b/samples/network-visualiser/src/test/kotlin/net/corda/netmap/simulation/IRSSimulationTest.kt @@ -1,7 +1,7 @@ package net.corda.netmap.simulation import net.corda.core.getOrThrow -import net.corda.core.utilities.LogHelper +import net.corda.testing.LogHelper import org.junit.Test class IRSSimulationTest { diff --git a/core/src/main/kotlin/net/corda/core/utilities/Logging.kt b/test-utils/src/main/kotlin/net/corda/testing/LogHelper.kt similarity index 80% rename from core/src/main/kotlin/net/corda/core/utilities/Logging.kt rename to test-utils/src/main/kotlin/net/corda/testing/LogHelper.kt index f17b1cc5e7..ad2e488e91 100644 --- a/core/src/main/kotlin/net/corda/core/utilities/Logging.kt +++ b/test-utils/src/main/kotlin/net/corda/testing/LogHelper.kt @@ -1,26 +1,12 @@ -package net.corda.core.utilities +package net.corda.testing import org.apache.logging.log4j.Level import org.apache.logging.log4j.LogManager import org.apache.logging.log4j.core.LoggerContext import org.apache.logging.log4j.core.config.Configurator import org.apache.logging.log4j.core.config.LoggerConfig -import org.slf4j.LoggerFactory import kotlin.reflect.KClass -// A couple of inlined utility functions: the first is just a syntax convenience, the second lets us use -// Kotlin's string interpolation efficiently: the message is never calculated/concatenated together unless -// logging at that level is enabled. -inline fun loggerFor(): org.slf4j.Logger = LoggerFactory.getLogger(T::class.java) - -inline fun org.slf4j.Logger.trace(msg: () -> String) { - if (isTraceEnabled) trace(msg()) -} - -inline fun org.slf4j.Logger.debug(msg: () -> String) { - if (isDebugEnabled) debug(msg()) -} - /** A configuration helper that allows modifying the log level for specific loggers */ object LogHelper { /**