mirror of
https://github.com/corda/corda.git
synced 2025-06-01 07:00:54 +00:00
[ENT-2678] PluginRegistrationTest is failing (fix) (OS part) (#4153)
This commit is contained in:
parent
66116e8d20
commit
24e9ceac48
@ -1,13 +1,12 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<Configuration status="info">
|
<Configuration status="info" packages="net.corda.cliutils">
|
||||||
|
|
||||||
<Properties>
|
<Properties>
|
||||||
<Property name="log-path">${sys:log-path:-logs}</Property>
|
<Property name="log-path">${sys:log-path:-logs}</Property>
|
||||||
<Property name="log-name">node-${hostName}</Property>
|
<Property name="log-name">node-${hostName}</Property>
|
||||||
<Property name="archive">${log-path}/archive</Property>
|
<Property name="archive">${log-path}/archive</Property>
|
||||||
<Property name="defaultLogLevel">${sys:log4j2.level:-info}</Property>
|
<Property name="defaultLogLevel">${sys:defaultLogLevel:-info}</Property>
|
||||||
<Property name="consoleLogLevel">${sys:consoleLogLevel:-error}</Property>
|
<Property name="consoleLogLevel">${sys:consoleLogLevel:-error}</Property>
|
||||||
<Property name="fileLogLevel">${sys:fileLogLevel:-${defaultLogLevel}}</Property>
|
|
||||||
</Properties>
|
</Properties>
|
||||||
|
|
||||||
<Appenders>
|
<Appenders>
|
||||||
@ -78,7 +77,7 @@
|
|||||||
<Loggers>
|
<Loggers>
|
||||||
<Root level="${defaultLogLevel}">
|
<Root level="${defaultLogLevel}">
|
||||||
<AppenderRef ref="Console-Appender" level="${consoleLogLevel}"/>
|
<AppenderRef ref="Console-Appender" level="${consoleLogLevel}"/>
|
||||||
<AppenderRef ref="RollingFile-Appender" level="${fileLogLevel}"/>
|
<AppenderRef ref="RollingFile-Appender"/>
|
||||||
</Root>
|
</Root>
|
||||||
<Logger name="BasicInfo" additivity="false">
|
<Logger name="BasicInfo" additivity="false">
|
||||||
<AppenderRef ref="Console-Appender-Println"/>
|
<AppenderRef ref="Console-Appender-Println"/>
|
||||||
|
@ -0,0 +1,48 @@
|
|||||||
|
package net.corda.node.logging
|
||||||
|
|
||||||
|
import net.corda.core.flows.FlowLogic
|
||||||
|
import net.corda.core.flows.InitiatingFlow
|
||||||
|
import net.corda.core.flows.StartableByRPC
|
||||||
|
import net.corda.core.internal.div
|
||||||
|
import net.corda.core.messaging.FlowHandle
|
||||||
|
import net.corda.core.messaging.startFlow
|
||||||
|
import net.corda.core.utilities.getOrThrow
|
||||||
|
import net.corda.testing.driver.DriverParameters
|
||||||
|
import net.corda.testing.driver.NodeHandle
|
||||||
|
import net.corda.testing.driver.driver
|
||||||
|
import org.assertj.core.api.Assertions.assertThat
|
||||||
|
import org.junit.Test
|
||||||
|
import java.io.File
|
||||||
|
|
||||||
|
class ErrorCodeLoggingTests {
|
||||||
|
@Test
|
||||||
|
fun `log entries with a throwable and ERROR or WARN get an error code appended`() {
|
||||||
|
driver(DriverParameters(notarySpecs = emptyList())) {
|
||||||
|
val node = startNode(startInSameProcess = false).getOrThrow()
|
||||||
|
node.rpc.startFlow(::MyFlow).waitForCompletion()
|
||||||
|
val logFile = node.logFile()
|
||||||
|
|
||||||
|
val linesWithErrorCode = logFile.useLines { lines -> lines.filter { line -> line.contains("[errorCode=") }.toList() }
|
||||||
|
|
||||||
|
assertThat(linesWithErrorCode).isNotEmpty
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@StartableByRPC
|
||||||
|
@InitiatingFlow
|
||||||
|
class MyFlow : FlowLogic<String>() {
|
||||||
|
override fun call(): String {
|
||||||
|
throw IllegalArgumentException("Mwahahahah")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun FlowHandle<*>.waitForCompletion() {
|
||||||
|
try {
|
||||||
|
returnValue.getOrThrow()
|
||||||
|
} catch (e: Exception) {
|
||||||
|
// This is expected to throw an exception, using getOrThrow() just to wait until done.
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun NodeHandle.logFile(): File = (baseDirectory / "logs").toFile().walk().filter { it.name.startsWith("node-") && it.extension == "log" }.single()
|
@ -426,10 +426,9 @@ interface NodeStartupLogging {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun CliWrapperBase.initLogging(baseDirectory: Path) {
|
fun CliWrapperBase.initLogging(baseDirectory: Path) {
|
||||||
val loggingLevel = loggingLevel.name.toLowerCase(Locale.ENGLISH)
|
System.setProperty("defaultLogLevel", specifiedLogLevel) // These properties are referenced from the XML config file.
|
||||||
System.setProperty("defaultLogLevel", loggingLevel) // These properties are referenced from the XML config file.
|
|
||||||
if (verbose) {
|
if (verbose) {
|
||||||
System.setProperty("consoleLogLevel", loggingLevel)
|
System.setProperty("consoleLogLevel", specifiedLogLevel)
|
||||||
Node.renderBasicInfoToConsole = false
|
Node.renderBasicInfoToConsole = false
|
||||||
}
|
}
|
||||||
System.setProperty("log-path", (baseDirectory / NodeCliCommand.LOGS_DIRECTORY_NAME).toString())
|
System.setProperty("log-path", (baseDirectory / NodeCliCommand.LOGS_DIRECTORY_NAME).toString())
|
||||||
|
@ -17,7 +17,7 @@ import java.nio.file.Path
|
|||||||
|
|
||||||
internal class ValidateConfigurationCli : CliWrapperBase("validate-configuration", "Validate the configuration without starting the node.") {
|
internal class ValidateConfigurationCli : CliWrapperBase("validate-configuration", "Validate the configuration without starting the node.") {
|
||||||
internal companion object {
|
internal companion object {
|
||||||
private val logger = loggerFor<ValidateConfigurationCli>()
|
private val logger by lazy { loggerFor<ValidateConfigurationCli>() }
|
||||||
|
|
||||||
internal fun logConfigurationErrors(errors: Iterable<Exception>, configFile: Path) {
|
internal fun logConfigurationErrors(errors: Iterable<Exception>, configFile: Path) {
|
||||||
errors.forEach { error ->
|
errors.forEach { error ->
|
||||||
@ -56,7 +56,7 @@ internal class ValidateConfigurationCli : CliWrapperBase("validate-configuration
|
|||||||
internal fun SharedNodeCmdLineOptions.nodeConfiguration(): Valid<NodeConfiguration> = NodeConfigurationParser.invoke(this)
|
internal fun SharedNodeCmdLineOptions.nodeConfiguration(): Valid<NodeConfiguration> = NodeConfigurationParser.invoke(this)
|
||||||
|
|
||||||
private object NodeConfigurationParser : (SharedNodeCmdLineOptions) -> Valid<NodeConfiguration> {
|
private object NodeConfigurationParser : (SharedNodeCmdLineOptions) -> Valid<NodeConfiguration> {
|
||||||
private val logger = loggerFor<ValidateConfigurationCli>()
|
private val logger by lazy { loggerFor<ValidateConfigurationCli>() }
|
||||||
|
|
||||||
private val configRenderingOptions = ConfigRenderOptions.defaults().setComments(false).setOriginComments(false).setFormatted(true)
|
private val configRenderingOptions = ConfigRenderOptions.defaults().setComments(false).setOriginComments(false).setFormatted(true)
|
||||||
|
|
||||||
|
@ -1,2 +1,2 @@
|
|||||||
Log4jContextSelector=net.corda.node.utilities.logging.AsyncLoggerContextSelectorNoThreadLocal
|
log4jContextSelector=net.corda.node.utilities.logging.AsyncLoggerContextSelectorNoThreadLocal
|
||||||
AsyncLogger.RingBufferSize=262144
|
AsyncLogger.RingBufferSize=262144
|
@ -137,10 +137,9 @@ abstract class CliWrapperBase(val alias: String, val description: String) : Call
|
|||||||
// This needs to be called before loggers (See: NodeStartup.kt:51 logger called by lazy, initLogging happens before).
|
// This needs to be called before loggers (See: NodeStartup.kt:51 logger called by lazy, initLogging happens before).
|
||||||
// Node's logging is more rich. In corda configurations two properties, defaultLoggingLevel and consoleLogLevel, are usually used.
|
// Node's logging is more rich. In corda configurations two properties, defaultLoggingLevel and consoleLogLevel, are usually used.
|
||||||
open fun initLogging() {
|
open fun initLogging() {
|
||||||
val loggingLevel = loggingLevel.name.toLowerCase(Locale.ENGLISH)
|
System.setProperty("defaultLogLevel", specifiedLogLevel) // These properties are referenced from the XML config file.
|
||||||
System.setProperty("defaultLogLevel", loggingLevel) // These properties are referenced from the XML config file.
|
|
||||||
if (verbose) {
|
if (verbose) {
|
||||||
System.setProperty("consoleLogLevel", loggingLevel)
|
System.setProperty("consoleLogLevel", specifiedLogLevel)
|
||||||
}
|
}
|
||||||
System.setProperty("log-path", Paths.get(".").toString())
|
System.setProperty("log-path", Paths.get(".").toString())
|
||||||
}
|
}
|
||||||
@ -154,6 +153,8 @@ abstract class CliWrapperBase(val alias: String, val description: String) : Call
|
|||||||
logger.info("Application Args: ${args.joinToString(" ")}")
|
logger.info("Application Args: ${args.joinToString(" ")}")
|
||||||
return runProgram()
|
return runProgram()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val specifiedLogLevel: String by lazy { System.getProperty("log4j2.level")?.toLowerCase(Locale.ENGLISH) ?: loggingLevel.name.toLowerCase(Locale.ENGLISH) }
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -10,9 +10,8 @@ import org.apache.logging.log4j.core.config.xml.XmlConfiguration
|
|||||||
import org.apache.logging.log4j.core.impl.LogEventFactory
|
import org.apache.logging.log4j.core.impl.LogEventFactory
|
||||||
|
|
||||||
@Plugin(name = "CordaLog4j2ConfigFactory", category = "ConfigurationFactory")
|
@Plugin(name = "CordaLog4j2ConfigFactory", category = "ConfigurationFactory")
|
||||||
@Order(10)
|
@Order(Integer.MAX_VALUE)
|
||||||
class CordaLog4j2ConfigFactory : ConfigurationFactory() {
|
class CordaLog4j2ConfigFactory : ConfigurationFactory() {
|
||||||
|
|
||||||
private companion object {
|
private companion object {
|
||||||
private val SUPPORTED_TYPES = arrayOf(".xml", "*")
|
private val SUPPORTED_TYPES = arrayOf(".xml", "*")
|
||||||
}
|
}
|
||||||
@ -22,13 +21,13 @@ class CordaLog4j2ConfigFactory : ConfigurationFactory() {
|
|||||||
override fun getSupportedTypes() = SUPPORTED_TYPES
|
override fun getSupportedTypes() = SUPPORTED_TYPES
|
||||||
|
|
||||||
private class ErrorCodeAppendingConfiguration(loggerContext: LoggerContext, source: ConfigurationSource) : XmlConfiguration(loggerContext, source) {
|
private class ErrorCodeAppendingConfiguration(loggerContext: LoggerContext, source: ConfigurationSource) : XmlConfiguration(loggerContext, source) {
|
||||||
|
|
||||||
override fun doConfigure() {
|
override fun doConfigure() {
|
||||||
|
|
||||||
super.doConfigure()
|
super.doConfigure()
|
||||||
loggers.values.forEach {
|
loggers.values.forEach {
|
||||||
val existingFactory = it.logEventFactory
|
val existingFactory = it.logEventFactory
|
||||||
it.logEventFactory = LogEventFactory { loggerName, marker, fqcn, level, message, properties, error -> existingFactory.createEvent(loggerName, marker, fqcn, level, message?.withErrorCodeFor(error, level), properties, error) }
|
it.logEventFactory = LogEventFactory { loggerName, marker, fqcn, level, message, properties, error ->
|
||||||
|
existingFactory.createEvent(loggerName, marker, fqcn, level, message?.withErrorCodeFor(error, level), properties, error)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user