From 8b7275eb97fe345ad004c426dbb78f89fa0c866d Mon Sep 17 00:00:00 2001 From: James Higgs <45565019+JamesHR3@users.noreply.github.com> Date: Wed, 10 Jun 2020 10:45:50 +0100 Subject: [PATCH 1/3] EG-2564 - Move printed error to logger (#6323) --- node/src/main/kotlin/net/corda/node/internal/NodeStartup.kt | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/node/src/main/kotlin/net/corda/node/internal/NodeStartup.kt b/node/src/main/kotlin/net/corda/node/internal/NodeStartup.kt index d9167e2816..8d6c343be1 100644 --- a/node/src/main/kotlin/net/corda/node/internal/NodeStartup.kt +++ b/node/src/main/kotlin/net/corda/node/internal/NodeStartup.kt @@ -333,8 +333,7 @@ open class NodeStartup : NodeStartupLogging { if (devMode) return true if (!certDirectory.isDirectory()) { - printError("Unable to access certificates directory ${certDirectory}. This could be because the node has not been registered with the Identity Operator.") - printError("Node will now shutdown.") + logger.error("Unable to access certificates directory ${certDirectory}. This could be because the node has not been registered with the Identity Operator. Node will now shutdown") return false } return true From 58af87c9883fa0248f4b5afe8d4f72ca983923c5 Mon Sep 17 00:00:00 2001 From: James Higgs <45565019+JamesHR3@users.noreply.github.com> Date: Wed, 10 Jun 2020 10:46:57 +0100 Subject: [PATCH 2/3] EG-2225 - Create log directory in correct place with verbose flag set (#6321) * Ensure logs directory is written to correct location * Remove a superfluous set of log path property * Add a unit test to catch bad log paths * Address detekt issues --- .../net/corda/node/internal/NodeStartup.kt | 2 +- .../corda/node/internal/NodeStartupCliTest.kt | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/node/src/main/kotlin/net/corda/node/internal/NodeStartup.kt b/node/src/main/kotlin/net/corda/node/internal/NodeStartup.kt index 8d6c343be1..2d38ef235d 100644 --- a/node/src/main/kotlin/net/corda/node/internal/NodeStartup.kt +++ b/node/src/main/kotlin/net/corda/node/internal/NodeStartup.kt @@ -503,6 +503,7 @@ interface NodeStartupLogging { fun CliWrapperBase.initLogging(baseDirectory: Path): Boolean { System.setProperty("defaultLogLevel", specifiedLogLevel) // These properties are referenced from the XML config file. + System.setProperty("log-path", (baseDirectory / NodeCliCommand.LOGS_DIRECTORY_NAME).toString()) if (verbose) { System.setProperty("consoleLoggingEnabled", "true") System.setProperty("consoleLogLevel", specifiedLogLevel) @@ -525,7 +526,6 @@ fun CliWrapperBase.initLogging(baseDirectory: Path): Boolean { return false } - System.setProperty("log-path", (baseDirectory / NodeCliCommand.LOGS_DIRECTORY_NAME).toString()) SLF4JBridgeHandler.removeHandlersForRootLogger() // The default j.u.l config adds a ConsoleHandler. SLF4JBridgeHandler.install() return true diff --git a/node/src/test/kotlin/net/corda/node/internal/NodeStartupCliTest.kt b/node/src/test/kotlin/net/corda/node/internal/NodeStartupCliTest.kt index 8fc0154f37..769835bfff 100644 --- a/node/src/test/kotlin/net/corda/node/internal/NodeStartupCliTest.kt +++ b/node/src/test/kotlin/net/corda/node/internal/NodeStartupCliTest.kt @@ -2,14 +2,19 @@ package net.corda.node.internal import net.corda.cliutils.CommonCliConstants import net.corda.core.internal.div +import net.corda.core.internal.exists import net.corda.nodeapi.internal.config.UnknownConfigKeysPolicy import org.assertj.core.api.Assertions import org.junit.BeforeClass import org.junit.Test +import org.slf4j.LoggerFactory import org.slf4j.event.Level import picocli.CommandLine +import java.nio.file.Files import java.nio.file.Path import java.nio.file.Paths +import kotlin.test.assertFalse +import kotlin.test.assertTrue class NodeStartupCliTest { private val startup = NodeStartupCli() @@ -49,4 +54,17 @@ class NodeStartupCliTest { Assertions.assertThat(startup.cmdLineOptions.configFile).isEqualTo(workingDirectory / "another-base-dir" / "node.conf") Assertions.assertThat(startup.cmdLineOptions.networkRootTrustStorePathParameter).isEqualTo(null) } + + @Test(timeout=3_000) + fun `test logs are written to correct location correctly if verbose flag set`() { + val node = NodeStartupCli() + val dir = Files.createTempDirectory("verboseLoggingTest") + node.verbose = true + // With verbose set, initLogging can accidentally attempt to access a logger before all required system properties are set. This + // causes the logging config to be parsed too early, resulting in logs being written to the wrong directory + node.initLogging(dir) + LoggerFactory.getLogger("").debug("Test message") + assertTrue(dir.resolve("logs").exists()) + assertFalse(Paths.get("./logs").exists()) + } } \ No newline at end of file From 48ed9dbc6ba3247649a8747e320ba58fc1b450c9 Mon Sep 17 00:00:00 2001 From: Ryan Fowler Date: Wed, 10 Jun 2020 18:30:00 +0100 Subject: [PATCH 3/3] NOTICK: Fix IRSDemo code to wait for a response when updating day (#6329) --- .../main/kotlin/net.corda.irs/flows/UpdateBusinessDayFlow.kt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/samples/irs-demo/cordapp/workflows-irs/src/main/kotlin/net.corda.irs/flows/UpdateBusinessDayFlow.kt b/samples/irs-demo/cordapp/workflows-irs/src/main/kotlin/net.corda.irs/flows/UpdateBusinessDayFlow.kt index 428641f238..eebd2c79d6 100644 --- a/samples/irs-demo/cordapp/workflows-irs/src/main/kotlin/net.corda.irs/flows/UpdateBusinessDayFlow.kt +++ b/samples/irs-demo/cordapp/workflows-irs/src/main/kotlin/net.corda.irs/flows/UpdateBusinessDayFlow.kt @@ -27,6 +27,7 @@ object UpdateBusinessDayFlow { override fun call() { val message = otherPartySession.receive().unwrap { it } (serviceHub.clock as DemoClock).updateDate(message.date) + otherPartySession.send(true) // Let's Broadcast know we've updated the clock } } @@ -64,7 +65,7 @@ object UpdateBusinessDayFlow { @Suspendable private fun doNextRecipient(recipient: Party) { - initiateFlow(recipient).send(UpdateBusinessDayMessage(date)) + initiateFlow(recipient).sendAndReceive(UpdateBusinessDayMessage(date)) } } } \ No newline at end of file