mirror of
https://github.com/corda/corda.git
synced 2024-12-18 20:47:57 +00:00
Corda-1155 - Jolokia logging via slf4j (#2753)
* Jolokia logging through slf4j * review remarks
This commit is contained in:
parent
5bd1ba0f39
commit
0d4e99d4f1
@ -60,5 +60,9 @@
|
|||||||
<Logger name="org.apache.activemq.artemis.core.server" level="error" additivity="false">
|
<Logger name="org.apache.activemq.artemis.core.server" level="error" additivity="false">
|
||||||
<AppenderRef ref="RollingFile-Appender"/>
|
<AppenderRef ref="RollingFile-Appender"/>
|
||||||
</Logger>
|
</Logger>
|
||||||
|
<Logger name="org.jolokia" additivity="true" level="warn">
|
||||||
|
<AppenderRef ref="Console-Appender-Println"/>
|
||||||
|
<AppenderRef ref="RollingFile-Appender" />
|
||||||
|
</Logger>
|
||||||
</Loggers>
|
</Loggers>
|
||||||
</Configuration>
|
</Configuration>
|
||||||
|
@ -44,7 +44,7 @@ fun main(args: Array<String>) {
|
|||||||
println("Finished starting nodes")
|
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 abstract fun acceptNodeConf(nodeConf: File): Boolean
|
||||||
internal fun acceptDirAndStartProcess(dir: File, headless: Boolean, javaArgs: List<String>, jvmArgs: List<String>): Process? {
|
internal fun acceptDirAndStartProcess(dir: File, headless: Boolean, javaArgs: List<String>, jvmArgs: List<String>): Process? {
|
||||||
if (!File(dir, jarName).exists()) {
|
if (!File(dir, jarName).exists()) {
|
||||||
@ -64,12 +64,12 @@ private abstract class JarType(internal val jarName: String) {
|
|||||||
internal abstract val headlessArgs: List<String>
|
internal abstract val headlessArgs: List<String>
|
||||||
}
|
}
|
||||||
|
|
||||||
private object NodeJarType : JarType("corda.jar") {
|
private object NodeJarType : JarType("corda.jar", jolokiaLogHandler = "net.corda.node.JolokiaSlf4Adapter") {
|
||||||
override fun acceptNodeConf(nodeConf: File) = true
|
override fun acceptNodeConf(nodeConf: File) = true
|
||||||
override val headlessArgs = listOf("--no-local-shell")
|
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
|
// 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 fun acceptNodeConf(nodeConf: File) = Files.lines(nodeConf.toPath()).anyMatch { "webAddress" in it }
|
||||||
override val headlessArgs = emptyList<String>()
|
override val headlessArgs = emptyList<String>()
|
||||||
@ -82,7 +82,8 @@ private abstract class JavaCommand(
|
|||||||
monitoringPort: Int?,
|
monitoringPort: Int?,
|
||||||
internal val nodeName: String,
|
internal val nodeName: String,
|
||||||
args: List<String>,
|
args: List<String>,
|
||||||
jvmArgs: List<String>
|
jvmArgs: List<String>,
|
||||||
|
jolokiaLoggerClass: String?
|
||||||
) {
|
) {
|
||||||
private val jolokiaJar by lazy {
|
private val jolokiaJar by lazy {
|
||||||
File("$dir/drivers").listFiles { _, filename ->
|
File("$dir/drivers").listFiles { _, filename ->
|
||||||
@ -94,9 +95,18 @@ private abstract class JavaCommand(
|
|||||||
add(getJavaPath())
|
add(getJavaPath())
|
||||||
addAll(jvmArgs)
|
addAll(jvmArgs)
|
||||||
add("-Dname=$nodeName")
|
add("-Dname=$nodeName")
|
||||||
|
|
||||||
val jvmArgs: MutableList<String> = mutableListOf()
|
val jvmArgs: MutableList<String> = mutableListOf()
|
||||||
null != debugPort && jvmArgs.add("-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=$debugPort")
|
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()) {
|
if (jvmArgs.isNotEmpty()) {
|
||||||
add("-Dcapsule.jvm.args=${jvmArgs.joinToString(separator = " ")}")
|
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<String>, jvmArgs: List<String>)
|
private class HeadlessJavaCommand(jarType: JarType, dir: File, debugPort: Int?, monitoringPort: Int?, args: List<String>, jvmArgs: List<String>)
|
||||||
: 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 processBuilder() = ProcessBuilder(command).redirectError(File("error.$nodeName.log")).inheritIO()
|
||||||
override fun getJavaPath() = File(File(System.getProperty("java.home"), "bin"), "java").path
|
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<String>, jvmArgs: List<String>)
|
private class TerminalWindowJavaCommand(jarType: JarType, dir: File, debugPort: Int?, monitoringPort: Int?, args: List<String>, jvmArgs: List<String>)
|
||||||
: 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) {
|
override fun processBuilder() = ProcessBuilder(when (os) {
|
||||||
OS.MACOS -> {
|
OS.MACOS -> {
|
||||||
listOf("osascript", "-e", """tell app "Terminal"
|
listOf("osascript", "-e", """tell app "Terminal"
|
||||||
|
@ -182,7 +182,7 @@ dependencies {
|
|||||||
testCompile "org.glassfish.jersey.containers:jersey-container-jetty-http:${jersey_version}"
|
testCompile "org.glassfish.jersey.containers:jersey-container-jetty-http:${jersey_version}"
|
||||||
|
|
||||||
// Jolokia JVM monitoring agent
|
// Jolokia JVM monitoring agent
|
||||||
runtime "org.jolokia:jolokia-jvm:${jolokia_version}:agent"
|
compile "org.jolokia:jolokia-jvm:${jolokia_version}:agent"
|
||||||
}
|
}
|
||||||
|
|
||||||
task integrationTest(type: Test) {
|
task integrationTest(type: Test) {
|
||||||
|
40
node/src/main/kotlin/net/corda/node/JolokiaSlf4Adapter.kt
Normal file
40
node/src/main/kotlin/net/corda/node/JolokiaSlf4Adapter.kt
Normal file
@ -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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
@ -25,5 +25,9 @@
|
|||||||
<Logger name="org.hibernate.SQL" level="info" additivity="false">
|
<Logger name="org.hibernate.SQL" level="info" additivity="false">
|
||||||
<AppenderRef ref="Console-Appender"/>
|
<AppenderRef ref="Console-Appender"/>
|
||||||
</Logger>
|
</Logger>
|
||||||
|
<Logger name="org.jolokia" additivity="true" level="warn">
|
||||||
|
<AppenderRef ref="Console-Appender-Println"/>
|
||||||
|
<AppenderRef ref="RollingFile-Appender" />
|
||||||
|
</Logger>
|
||||||
</Loggers>
|
</Loggers>
|
||||||
</Configuration>
|
</Configuration>
|
||||||
|
@ -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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user