org.apache.logging.log4j.core.appender.AbstractOutputStreamAppender Java Examples

The following examples show how to use org.apache.logging.log4j.core.appender.AbstractOutputStreamAppender. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: StartupLoggingUtils.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
/**
 * 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();
      }
    }
  }
}
 
Example #2
Source File: LoggingUtils.java    From FunnyGuilds with Apache License 2.0 5 votes vote down vote up
public static void flushLogger(Logger rootLogger) {
    rootLogger.getAppenders().values()
              .stream()
              .filter(appender -> appender instanceof AbstractOutputStreamAppender)
              .map(appender -> (AbstractOutputStreamAppender) appender)
              .filter(appender -> ! appender.getImmediateFlush())
              .forEach(appender -> appender.getManager().flush());
}