diff --git a/config/dev/log4j2.xml b/config/dev/log4j2.xml
index 0ad0431e4d..f0ec5b615d 100644
--- a/config/dev/log4j2.xml
+++ b/config/dev/log4j2.xml
@@ -60,5 +60,9 @@
+
+
+
+
diff --git a/gradle-plugins/cordformation/src/noderunner/kotlin/net/corda/plugins/NodeRunner.kt b/gradle-plugins/cordformation/src/noderunner/kotlin/net/corda/plugins/NodeRunner.kt
index d3adb84a10..c3e28898e2 100644
--- a/gradle-plugins/cordformation/src/noderunner/kotlin/net/corda/plugins/NodeRunner.kt
+++ b/gradle-plugins/cordformation/src/noderunner/kotlin/net/corda/plugins/NodeRunner.kt
@@ -44,7 +44,7 @@ fun main(args: Array) {
println("Finished starting nodes")
}
-private abstract class JarType(internal val jarName: String) {
+private abstract class JarType(internal val jarName: String, internal val jolokiaLogHandler: String? = null) {
internal abstract fun acceptNodeConf(nodeConf: File): Boolean
internal fun acceptDirAndStartProcess(dir: File, headless: Boolean, javaArgs: List, jvmArgs: List): Process? {
if (!File(dir, jarName).exists()) {
@@ -64,12 +64,12 @@ private abstract class JarType(internal val jarName: String) {
internal abstract val headlessArgs: List
}
-private object NodeJarType : JarType("corda.jar") {
+private object NodeJarType : JarType("corda.jar", jolokiaLogHandler = "net.corda.node.JolokiaSlf4Adapter") {
override fun acceptNodeConf(nodeConf: File) = true
override val headlessArgs = listOf("--no-local-shell")
}
-private object WebJarType : JarType("corda-webserver.jar") {
+private object WebJarType : JarType(jarName = "corda-webserver.jar", jolokiaLogHandler = "net.corda.webserver.JolokiaSlf4Adapter") {
// TODO: Add a webserver.conf, or use TypeSafe config instead of this hack
override fun acceptNodeConf(nodeConf: File) = Files.lines(nodeConf.toPath()).anyMatch { "webAddress" in it }
override val headlessArgs = emptyList()
@@ -82,7 +82,8 @@ private abstract class JavaCommand(
monitoringPort: Int?,
internal val nodeName: String,
args: List,
- jvmArgs: List
+ jvmArgs: List,
+ jolokiaLoggerClass: String?
) {
private val jolokiaJar by lazy {
File("$dir/drivers").listFiles { _, filename ->
@@ -94,9 +95,18 @@ private abstract class JavaCommand(
add(getJavaPath())
addAll(jvmArgs)
add("-Dname=$nodeName")
+
val jvmArgs: MutableList = mutableListOf()
null != debugPort && jvmArgs.add("-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=$debugPort")
- null != monitoringPort && jvmArgs.add("-javaagent:drivers/$jolokiaJar=port=$monitoringPort")
+
+ if(null != monitoringPort) {
+ val jolokiaConfig = java.lang.StringBuilder()
+ jolokiaConfig.append("-javaagent:drivers/$jolokiaJar=port=$monitoringPort")
+ if(jolokiaLoggerClass != null) {
+ jolokiaConfig.append(",logHandlerClass=${jolokiaLoggerClass}")
+ }
+ jvmArgs.add(jolokiaConfig.toString())
+ }
if (jvmArgs.isNotEmpty()) {
add("-Dcapsule.jvm.args=${jvmArgs.joinToString(separator = " ")}")
}
@@ -111,13 +121,13 @@ private abstract class JavaCommand(
}
private class HeadlessJavaCommand(jarType: JarType, dir: File, debugPort: Int?, monitoringPort: Int?, args: List, jvmArgs: List)
- : JavaCommand(jarType.jarName, dir, debugPort, monitoringPort, dir.name, jarType.headlessArgs + args, jvmArgs) {
+ : JavaCommand(jarType.jarName, dir, debugPort, monitoringPort, dir.name, jarType.headlessArgs + args, jvmArgs, jarType.jolokiaLogHandler) {
override fun processBuilder() = ProcessBuilder(command).redirectError(File("error.$nodeName.log")).inheritIO()
override fun getJavaPath() = File(File(System.getProperty("java.home"), "bin"), "java").path
}
private class TerminalWindowJavaCommand(jarType: JarType, dir: File, debugPort: Int?, monitoringPort: Int?, args: List, jvmArgs: List)
- : JavaCommand(jarType.jarName, dir, debugPort, monitoringPort, "${dir.name}-${jarType.jarName}", args, jvmArgs) {
+ : JavaCommand(jarType.jarName, dir, debugPort, monitoringPort, "${dir.name}-${jarType.jarName}", args, jvmArgs, jarType.jolokiaLogHandler) {
override fun processBuilder() = ProcessBuilder(when (os) {
OS.MACOS -> {
listOf("osascript", "-e", """tell app "Terminal"
diff --git a/node/build.gradle b/node/build.gradle
index 05a19116a5..224794f5bf 100644
--- a/node/build.gradle
+++ b/node/build.gradle
@@ -182,7 +182,7 @@ dependencies {
testCompile "org.glassfish.jersey.containers:jersey-container-jetty-http:${jersey_version}"
// Jolokia JVM monitoring agent
- runtime "org.jolokia:jolokia-jvm:${jolokia_version}:agent"
+ compile "org.jolokia:jolokia-jvm:${jolokia_version}:agent"
}
task integrationTest(type: Test) {
diff --git a/node/src/main/kotlin/net/corda/node/JolokiaSlf4Adapter.kt b/node/src/main/kotlin/net/corda/node/JolokiaSlf4Adapter.kt
new file mode 100644
index 0000000000..350d9c4fac
--- /dev/null
+++ b/node/src/main/kotlin/net/corda/node/JolokiaSlf4Adapter.kt
@@ -0,0 +1,40 @@
+package net.corda.node
+
+import org.jolokia.util.LogHandler
+import org.slf4j.Logger
+import org.slf4j.LoggerFactory
+
+/**
+ * This also exists in webserver, because depends on jolokia
+ **/
+class JolokiaSlf4Adapter : LogHandler {
+ companion object {
+ val log: Logger = LoggerFactory.getLogger("org.jolokia")
+ }
+
+ override fun error(message: String?, t: Throwable?) {
+ if (message != null) {
+ if (t != null) {
+ log.error(message, t)
+ } else {
+ log.error(message)
+ }
+ } else if (t != null) {
+ log.error("Exception without a comment", t)
+ }
+ }
+
+ override fun debug(message: String?) {
+ if (message != null) {
+ log.debug(message)
+ }
+ }
+
+ override fun info(message: String?) {
+ if (message != null) {
+ log.info(message)
+ }
+ }
+
+
+}
diff --git a/testing/test-common/src/main/resources/log4j2-test.xml b/testing/test-common/src/main/resources/log4j2-test.xml
index 0cfee94d15..994cfc5e57 100644
--- a/testing/test-common/src/main/resources/log4j2-test.xml
+++ b/testing/test-common/src/main/resources/log4j2-test.xml
@@ -25,5 +25,9 @@
+
+
+
+
diff --git a/webserver/src/main/kotlin/net/corda/webserver/JolokiaSlf4Adapter.kt b/webserver/src/main/kotlin/net/corda/webserver/JolokiaSlf4Adapter.kt
new file mode 100644
index 0000000000..5e54e0f98e
--- /dev/null
+++ b/webserver/src/main/kotlin/net/corda/webserver/JolokiaSlf4Adapter.kt
@@ -0,0 +1,40 @@
+package net.corda.webserver
+
+import org.jolokia.util.LogHandler
+import org.slf4j.Logger
+import org.slf4j.LoggerFactory
+
+/**
+ * This also exists in node, because depends on jolokia
+ **/
+class JolokiaSlf4Adapter : LogHandler {
+ companion object {
+ val log: Logger = LoggerFactory.getLogger("org.jolokia")
+ }
+
+ override fun error(message: String?, t: Throwable?) {
+ if (message != null) {
+ if (t != null) {
+ log.error(message, t)
+ } else {
+ log.error(message)
+ }
+ } else if (t != null) {
+ log.error("Exception without a comment", t)
+ }
+ }
+
+ override fun debug(message: String?) {
+ if (message != null) {
+ log.debug(message)
+ }
+ }
+
+ override fun info(message: String?) {
+ if (message != null) {
+ log.info(message)
+ }
+ }
+
+
+}