mirror of
https://github.com/corda/corda.git
synced 2024-12-19 21:17:58 +00:00
CORDA-3845: Update BC, log4j, slf4j (#6464)
* CORDA-3845: Update BC to 1.64 * CORDA-3845: Upgraded log4j to 2.13.3 * We can remove the use of Manifests from the logging package so that when _it_ logs it doesn't error on the fact the stream was already closed by the default Java logger. * Some more tidy up * Remove the logging package as a plugin * latest BC version * Remove old test * fix up * Fix some rebased changes to log file handling * Fix some rebased changes to log file handling * Update slf4j too Co-authored-by: Adel El-Beik <adel.el-beik@r3.com>
This commit is contained in:
parent
4acf41ea3d
commit
2ca10464b7
@ -68,8 +68,8 @@ buildscript {
|
||||
ext.jersey_version = '2.25'
|
||||
ext.servlet_version = '4.0.1'
|
||||
ext.assertj_version = '3.12.2'
|
||||
ext.slf4j_version = '1.7.26'
|
||||
ext.log4j_version = '2.11.2'
|
||||
ext.slf4j_version = '1.7.30'
|
||||
ext.log4j_version = '2.13.3'
|
||||
ext.bouncycastle_version = constants.getProperty("bouncycastleVersion")
|
||||
ext.guava_version = constants.getProperty("guavaVersion")
|
||||
ext.caffeine_version = constants.getProperty("caffeineVersion")
|
||||
|
@ -1,28 +0,0 @@
|
||||
package net.corda.common.logging
|
||||
|
||||
import org.apache.logging.log4j.core.Core
|
||||
import org.apache.logging.log4j.core.LogEvent
|
||||
import org.apache.logging.log4j.core.appender.rewrite.RewritePolicy
|
||||
import org.apache.logging.log4j.core.config.plugins.Plugin
|
||||
import org.apache.logging.log4j.core.config.plugins.PluginFactory
|
||||
import org.apache.logging.log4j.core.impl.Log4jLogEvent
|
||||
|
||||
@Plugin(name = "ErrorCodeRewritePolicy", category = Core.CATEGORY_NAME, elementType = "rewritePolicy", printObject = false)
|
||||
class ErrorCodeRewritePolicy : RewritePolicy {
|
||||
override fun rewrite(source: LogEvent): LogEvent? {
|
||||
val newMessage = source.message?.withErrorCodeFor(source.thrown, source.level)
|
||||
return if (newMessage == source.message) {
|
||||
source
|
||||
} else {
|
||||
Log4jLogEvent.Builder(source).setMessage(newMessage).build()
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
@JvmStatic
|
||||
@PluginFactory
|
||||
fun createPolicy(): ErrorCodeRewritePolicy {
|
||||
return ErrorCodeRewritePolicy()
|
||||
}
|
||||
}
|
||||
}
|
@ -1,5 +1,5 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Configuration status="info" packages="net.corda.common.logging" shutdownHook="disable">
|
||||
<Configuration status="info" shutdownHook="disable">
|
||||
|
||||
<Properties>
|
||||
<Property name="log-path">${sys:log-path:-logs}</Property>
|
||||
@ -172,21 +172,17 @@
|
||||
|
||||
<Rewrite name="Console-ErrorCode-Selector">
|
||||
<AppenderRef ref="Console-Selector"/>
|
||||
<ErrorCodeRewritePolicy/>
|
||||
</Rewrite>
|
||||
|
||||
<Rewrite name="Console-ErrorCode-Appender-Println">
|
||||
<AppenderRef ref="Console-Appender-Println"/>
|
||||
<ErrorCodeRewritePolicy/>
|
||||
</Rewrite>
|
||||
|
||||
<Rewrite name="RollingFile-ErrorCode-Appender">
|
||||
<AppenderRef ref="RollingFile-Appender"/>
|
||||
<ErrorCodeRewritePolicy/>
|
||||
</Rewrite>
|
||||
<Rewrite name="Diagnostic-RollingFile-ErrorCode-Appender">
|
||||
<AppenderRef ref="Diagnostic-RollingFile-Appender"/>
|
||||
<ErrorCodeRewritePolicy/>
|
||||
</Rewrite>
|
||||
</Appenders>
|
||||
|
||||
|
@ -20,7 +20,7 @@ quasarClassifier=jdk8
|
||||
quasarVersion11=0.8.0_r3
|
||||
jdkClassifier11=jdk11
|
||||
proguardVersion=6.1.1
|
||||
bouncycastleVersion=1.60
|
||||
bouncycastleVersion=1.66
|
||||
classgraphVersion=4.8.78
|
||||
disruptorVersion=3.4.2
|
||||
typesafeConfigVersion=1.3.4
|
||||
|
@ -6,8 +6,8 @@ import net.corda.core.flows.StartableByRPC
|
||||
import net.corda.core.messaging.startFlow
|
||||
import net.corda.core.serialization.CheckpointCustomSerializer
|
||||
import net.corda.core.utilities.getOrThrow
|
||||
import net.corda.node.logging.logFile
|
||||
import net.corda.testing.driver.driver
|
||||
import net.corda.testing.driver.logFile
|
||||
import org.assertj.core.api.Assertions
|
||||
import org.junit.Test
|
||||
import java.time.Duration
|
||||
|
@ -7,9 +7,9 @@ import net.corda.core.messaging.startFlow
|
||||
import net.corda.core.serialization.CheckpointCustomSerializer
|
||||
import net.corda.core.serialization.CordaSerializable
|
||||
import net.corda.core.utilities.getOrThrow
|
||||
import net.corda.node.logging.logFile
|
||||
import net.corda.testing.driver.DriverParameters
|
||||
import net.corda.testing.driver.driver
|
||||
import net.corda.testing.driver.logFile
|
||||
import net.corda.testing.node.internal.enclosedCordapp
|
||||
import org.assertj.core.api.Assertions
|
||||
import org.junit.Test
|
||||
|
@ -1,68 +0,0 @@
|
||||
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(timeout=300_000)
|
||||
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=")
|
||||
}.filter { line ->
|
||||
line.contains("moreInformationAt=https://errors.corda.net/")
|
||||
}.toList()
|
||||
}
|
||||
|
||||
assertThat(linesWithErrorCode).isNotEmpty
|
||||
}
|
||||
}
|
||||
|
||||
// This is used to detect broken logging which can be caused by loggers being initialized
|
||||
// before the initLogging() call is made
|
||||
@Test(timeout=300_000)
|
||||
fun `When logging is set to error level, there are no other levels logged after node startup`() {
|
||||
driver(DriverParameters(notarySpecs = emptyList())) {
|
||||
val node = startNode(startInSameProcess = false, logLevelOverride = "ERROR").getOrThrow()
|
||||
val logFile = node.logFile()
|
||||
val lengthAfterStart = logFile.length()
|
||||
node.rpc.startFlow(::MyFlow).waitForCompletion()
|
||||
// An exception thrown in a flow will log at the "INFO" level.
|
||||
assertThat(logFile.length()).isEqualTo(lengthAfterStart)
|
||||
}
|
||||
}
|
||||
|
||||
@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.
|
||||
}
|
||||
}
|
||||
|
||||
fun NodeHandle.logFile(): File = (baseDirectory / "logs").toFile().walk().filter { it.name.startsWith("node-") && it.extension == "log" }.single()
|
@ -1,10 +1,10 @@
|
||||
package net.corda.node.services.config
|
||||
|
||||
import net.corda.core.utilities.getOrThrow
|
||||
import net.corda.node.logging.logFile
|
||||
import net.corda.testing.driver.DriverParameters
|
||||
import net.corda.testing.driver.driver
|
||||
import net.corda.testing.driver.internal.incrementalPortAllocation
|
||||
import net.corda.testing.driver.logFile
|
||||
import org.junit.Assert.assertTrue
|
||||
import org.junit.Test
|
||||
|
||||
|
@ -26,6 +26,7 @@ import net.corda.testing.node.internal.genericDriver
|
||||
import net.corda.testing.node.internal.getTimestampAsDirectoryName
|
||||
import net.corda.testing.node.internal.newContext
|
||||
import rx.Observable
|
||||
import java.io.File
|
||||
import java.nio.file.Path
|
||||
import java.nio.file.Paths
|
||||
import java.util.concurrent.atomic.AtomicInteger
|
||||
@ -66,6 +67,8 @@ interface NodeHandle : AutoCloseable {
|
||||
fun stop()
|
||||
}
|
||||
|
||||
fun NodeHandle.logFile(): File = (baseDirectory / "logs").toFile().walk().filter { it.name.startsWith("node-") && it.extension == "log" }.single()
|
||||
|
||||
/** Interface which represents an out of process node and exposes its process handle. **/
|
||||
@DoNotImplement
|
||||
interface OutOfProcess : NodeHandle {
|
||||
|
@ -1,5 +1,5 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Configuration status="info" packages="net.corda.common.logging">
|
||||
<Configuration status="info">
|
||||
|
||||
<Properties>
|
||||
<Property name="log-path">${sys:log-path:-logs}</Property>
|
||||
@ -63,17 +63,14 @@
|
||||
|
||||
<Rewrite name="Console-ErrorCode-Appender">
|
||||
<AppenderRef ref="Console-Appender"/>
|
||||
<ErrorCodeRewritePolicy/>
|
||||
</Rewrite>
|
||||
|
||||
<Rewrite name="Console-ErrorCode-Appender-Println">
|
||||
<AppenderRef ref="Console-Appender-Println"/>
|
||||
<ErrorCodeRewritePolicy/>
|
||||
</Rewrite>
|
||||
|
||||
<Rewrite name="RollingFile-ErrorCode-Appender">
|
||||
<AppenderRef ref="RollingFile-Appender"/>
|
||||
<ErrorCodeRewritePolicy/>
|
||||
</Rewrite>
|
||||
</Appenders>
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Configuration status="info" packages="net.corda.common.logging">
|
||||
<Configuration status="info">
|
||||
|
||||
<Properties>
|
||||
<Property name="log-path">${sys:log-path:-logs}</Property>
|
||||
@ -65,17 +65,14 @@
|
||||
|
||||
<Rewrite name="Console-ErrorCode-Appender">
|
||||
<AppenderRef ref="Console-Appender"/>
|
||||
<ErrorCodeRewritePolicy/>
|
||||
</Rewrite>
|
||||
|
||||
<Rewrite name="Console-ErrorCode-Appender-Println">
|
||||
<AppenderRef ref="Console-Appender-Println"/>
|
||||
<ErrorCodeRewritePolicy/>
|
||||
</Rewrite>
|
||||
|
||||
<Rewrite name="RollingFile-ErrorCode-Appender">
|
||||
<AppenderRef ref="RollingFile-Appender"/>
|
||||
<ErrorCodeRewritePolicy/>
|
||||
</Rewrite>
|
||||
</Appenders>
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user