Skip to content

Commit

Permalink
Merge pull request corda#2758 from corda/merge/CORDA-1155
Browse files Browse the repository at this point in the history
CORDA-1155 - Jolokia logging via slf4j (corda#2753)
  • Loading branch information
ags313 authored Mar 12, 2018
2 parents 3f73545 + ca54ed6 commit 9a0a0e9
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 1 deletion.
4 changes: 4 additions & 0 deletions config/dev/log4j2.xml
Original file line number Diff line number Diff line change
Expand Up @@ -60,5 +60,9 @@
<Logger name="org.apache.activemq.artemis.core.server" level="error" additivity="false">
<AppenderRef ref="RollingFile-Appender"/>
</Logger>
<Logger name="org.jolokia" additivity="true" level="warn">
<AppenderRef ref="Console-Appender-Println"/>
<AppenderRef ref="RollingFile-Appender" />
</Logger>
</Loggers>
</Configuration>
3 changes: 2 additions & 1 deletion node/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,8 @@ dependencies {
testCompile "org.glassfish.jersey.containers:jersey-container-servlet-core:${jersey_version}"
testCompile "org.glassfish.jersey.containers:jersey-container-jetty-http:${jersey_version}"

runtime "org.jolokia:jolokia-jvm:${jolokia_version}:agent"
// Jolokia JVM monitoring agent, required to push logs through slf4j
compile "org.jolokia:jolokia-jvm:${jolokia_version}:agent"
}

task integrationTest(type: Test) {
Expand Down
35 changes: 35 additions & 0 deletions node/src/main/kotlin/net/corda/node/JolokiaSlf4jAdapter.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package net.corda.node

import org.jolokia.util.LogHandler
import org.slf4j.Logger
import org.slf4j.LoggerFactory

class JolokiaSlf4jAdapter : 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)
}
}
}
3 changes: 3 additions & 0 deletions testing/test-common/src/main/resources/log4j2-test.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,8 @@
<Logger name="org.hibernate.SQL" level="info" additivity="false">

<AppenderRef ref="Console-Appender"/>

</Logger>
<Logger name="org.jolokia" additivity="true" level="warn">
<AppenderRef ref="Console-Appender-Println"/>
</Logger>
</Loggers>
</Configuration>

0 comments on commit 9a0a0e9

Please sign in to comment.