You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by er...@apache.org on 2019/03/18 18:54:24 UTC
[lucene-solr] branch branch_8x updated: SOLR-13268: Patch that
flushes when shutting down
This is an automated email from the ASF dual-hosted git repository.
erick pushed a commit to branch branch_8x
in repository https://gitbox.apache.org/repos/asf/lucene-solr.git
The following commit(s) were added to refs/heads/branch_8x by this push:
new 0894e39 SOLR-13268: Patch that flushes when shutting down
0894e39 is described below
commit 0894e39cebbc349968bee024b82792f1d433bbd7
Author: erick <er...@gmail.com>
AuthorDate: Mon Mar 18 11:53:54 2019 -0700
SOLR-13268: Patch that flushes when shutting down
---
.../org/apache/solr/util/StartupLoggingUtils.java | 34 +++++++++++++++++++++-
1 file changed, 33 insertions(+), 1 deletion(-)
diff --git a/solr/core/src/java/org/apache/solr/util/StartupLoggingUtils.java b/solr/core/src/java/org/apache/solr/util/StartupLoggingUtils.java
index 8181ae5..e5394b4 100644
--- a/solr/core/src/java/org/apache/solr/util/StartupLoggingUtils.java
+++ b/solr/core/src/java/org/apache/solr/util/StartupLoggingUtils.java
@@ -24,6 +24,7 @@ import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.core.Appender;
import org.apache.logging.log4j.core.LoggerContext;
+import org.apache.logging.log4j.core.appender.AbstractOutputStreamAppender;
import org.apache.logging.log4j.core.appender.ConsoleAppender;
import org.apache.logging.log4j.core.config.Configuration;
import org.apache.logging.log4j.core.config.LoggerConfig;
@@ -133,7 +134,8 @@ public final class StartupLoggingUtils {
* Tests are particularly sensitive to this call or the object release tracker will report "lmax.disruptor" not
* terminating when asynch logging (new default as of 8.1) is enabled.
*
- *
+ * Expert, there are rarely good reasons for this to be called outside of the test framework. If you are tempted to
+ * call this for running Solr, you should probably be using synchronous logging.
*/
@SuppressForbidden(reason = "Legitimate log4j2 access")
public static void shutdown() {
@@ -141,8 +143,38 @@ public final class StartupLoggingUtils {
logNotSupported("Not running log4j2, could not call shutdown for async logging.");
return;
}
+ flushAllLoggers();
LogManager.shutdown(true);
}
+
+ /**
+ * This is primarily for tests to insure that log messages don't bleed from one test case to another, see:
+ * SOLR-13268.
+ *
+ * However, if there are situations where we want to insure that all log messages for all loggers are flushed,
+ * this method can be called by anyone. It should _not_ affect Solr in any way except, perhaps, a slight delay
+ * while messages are being flushed.
+ *
+ * Expert, there are rarely good reasons for this to be called outside of the test framework. If you are tempted to
+ * call this for running Solr, you should probably be using synchronous logging.
+ */
+ @SuppressForbidden(reason = "Legitimate log4j2 access")
+ public static void flushAllLoggers() {
+ if (!isLog4jActive()) {
+ logNotSupported("Not running log4j2, could not call shutdown for async logging.");
+ return;
+ }
+
+ final LoggerContext logCtx = ((LoggerContext) LogManager.getContext(false));
+ for (final org.apache.logging.log4j.core.Logger logger : logCtx.getLoggers()) {
+ for (final Appender appender : logger.getAppenders().values()) {
+ if (appender instanceof AbstractOutputStreamAppender) {
+ ((AbstractOutputStreamAppender) appender).getManager().flush();
+ }
+ }
+ }
+ }
+
/**
* Return a string representing the current static ROOT logging level
* @return a string TRACE, DEBUG, WARN, ERROR or INFO representing current log level. Default is INFO