mirror of
https://github.com/corda/corda.git
synced 2024-12-18 20:47:57 +00:00
Moved loggerFor and other useful Kotlin extensions into KotilnUtils.kt and moved LogHelper into test-utils
This commit is contained in:
parent
8f1529b863
commit
984fbd8995
21
core/src/main/kotlin/net/corda/core/utilities/KotlinUtils.kt
Normal file
21
core/src/main/kotlin/net/corda/core/utilities/KotlinUtils.kt
Normal file
@ -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<MyClass>()`
|
||||
*/
|
||||
inline fun <reified T : Any> 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())
|
||||
}
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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 {
|
||||
|
@ -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 <reified T : Any> 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 {
|
||||
/**
|
Loading…
Reference in New Issue
Block a user