forked from corda/corda
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Corda-1931 Asynchronous logging (corda#3989)
* Provide AsyncLoggingContextSelector that inhibits use of thread local storage * Turn on async logging via log4j properties file * Mention async logging in the documentation and also explain how to turn it off when required. * Formatting * Typo * Add shutdown hook to flush loggers. * code review rework * Ring buffer size to 256kB * Set maximal log file size to 100MB - should slow down the rolling of log files and give us a bit more history on the cluster. The old limit of max 10GB of compressed log files still stands.
- Loading branch information
Showing
7 changed files
with
57 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
...c/main/kotlin/net/corda/node/utilities/logging/AsyncLoggerContextSelectorNoThreadLocal.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package net.corda.node.utilities.logging | ||
|
||
import net.corda.nodeapi.internal.addShutdownHook | ||
import org.apache.logging.log4j.LogManager | ||
import org.apache.logging.log4j.core.LoggerContext | ||
import org.apache.logging.log4j.core.async.AsyncLoggerContext | ||
import org.apache.logging.log4j.core.selector.ClassLoaderContextSelector | ||
import org.apache.logging.log4j.core.util.Constants | ||
import org.apache.logging.log4j.util.PropertiesUtil | ||
import java.net.URI | ||
|
||
class AsyncLoggerContextSelectorNoThreadLocal : ClassLoaderContextSelector() { | ||
companion object { | ||
/** | ||
* Returns `true` if the user specified this selector as the Log4jContextSelector, to make all loggers | ||
* asynchronous. | ||
* | ||
* @return `true` if all loggers are asynchronous, `false` otherwise. | ||
*/ | ||
@JvmStatic | ||
fun isSelected(): Boolean { | ||
return AsyncLoggerContextSelectorNoThreadLocal::class.java.name == PropertiesUtil.getProperties().getStringProperty(Constants.LOG4J_CONTEXT_SELECTOR) | ||
} | ||
} | ||
|
||
init { | ||
// if we use async log4j logging, we need to shut down the logging to flush the loggers on exit | ||
addShutdownHook { LogManager.shutdown() } | ||
} | ||
|
||
override fun createContext(name: String?, configLocation: URI?): LoggerContext { | ||
return AsyncLoggerContext(name, null, configLocation).also { it.setUseThreadLocals(false) } | ||
} | ||
|
||
override fun toContextMapKey(loader: ClassLoader?): String { | ||
// LOG4J2-666 ensure unique name across separate instances created by webapp classloaders | ||
return "AsyncContextNoThreadLocal@" + Integer.toHexString(System.identityHashCode(loader)) | ||
} | ||
|
||
override fun defaultContextName(): String { | ||
return "DefaultAsyncContextNoThreadLocal@" + Thread.currentThread().name | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
Log4jContextSelector=net.corda.node.utilities.logging.AsyncLoggerContextSelectorNoThreadLocal | ||
AsyncLogger.RingBufferSize=262144 |