mirror of
https://github.com/corda/corda.git
synced 2025-01-18 18:56:28 +00:00
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
This commit is contained in:
parent
8b7275eb97
commit
58af87c988
@ -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
|
||||
|
@ -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())
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user