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..2d38ef235d 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 @@ -504,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) @@ -526,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 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