當前位置: 首頁>>代碼示例>>Java>>正文


Java WriterAppender類代碼示例

本文整理匯總了Java中org.apache.logging.log4j.core.appender.WriterAppender的典型用法代碼示例。如果您正苦於以下問題:Java WriterAppender類的具體用法?Java WriterAppender怎麽用?Java WriterAppender使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


WriterAppender類屬於org.apache.logging.log4j.core.appender包,在下文中一共展示了WriterAppender類的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: addLoggingWriterAppender

import org.apache.logging.log4j.core.appender.WriterAppender; //導入依賴的package包/類
@Override
public StringWriter addLoggingWriterAppender(String appenderName)
{
    // Get the configuration
    final LoggerContext loggerContext = (LoggerContext) LogManager.getContext(false);
    final Configuration configuration = loggerContext.getConfiguration();

    // Create a string writer as part of the appender so logging will be written to it.
    StringWriter stringWriter = new StringWriter();

    // Create and start the appender with the string writer.
    Appender appender = WriterAppender.createAppender(null, null, stringWriter, appenderName, false, true);
    appender.start();

    // Add the appender to the root logger.
    configuration.getRootLogger().addAppender(appender, null, null);

    // Return the string writer.
    return stringWriter;
}
 
開發者ID:FINRAOS,項目名稱:herd,代碼行數:21,代碼來源:Log4j2LoggingHelper.java

示例2: CLogOut

import org.apache.logging.log4j.core.appender.WriterAppender; //導入依賴的package包/類
private CLogOut() {
    final ByteArrayOutputStream stdStream = new ByteArrayOutputStream() {
        @Override
        public synchronized void flush() throws IOException {
            String theString = toString("UTF-8");

            /* OK:
             Establishing connection.
             Twitter Stream consumer-1[Establishing connection]
             Connection established.
             Receiving status stream.
             Twitter Stream consumer-1[Receiving stream]
             *Received:{...}
             Twitter Stream consumer-1[Disposing thread]

             */

            /* WRONG:
             Establishing connection.
             Twitter Stream consumer-1[Establishing connection]
             Exceeded connection limit for user
             420
             Waiting for 10000 milliseconds
             Twitter Stream consumer-1[Disposing thread]

             */
            Platform.runLater(() -> {
                if (theString.startsWith("Establishing connection")) {
                    message.set("Establishing connection...\n Please, wait a few seconds");
                } else if (theString.startsWith("Receiving status stream")) {
                    message.set("Receiving tweets!! \n Press stop button to stop the search");
                } else if (theString.startsWith("Exceeded connection limit")) {
                    message.set("Exceeded connection limit...");
                } else if (theString.startsWith("Waiting for ")) {
                    message.set(theString + " or press stop button to stop the search");
                } else if (theString.contains("Disposing thread")) {
                    message.set("The search has finished");
                }
            });
            System.out.print("***** " + theString);
            reset();
        }
    };

    
    LoggerContext context = LoggerContext.getContext(false);
    Configuration config = context.getConfiguration();
    PatternLayout layout = PatternLayout.newBuilder().withConfiguration(config).withPattern("%m%n").build();
    Appender appender = WriterAppender.newBuilder().setLayout(layout).setTarget(new OutputStreamWriter(stdStream, StandardCharsets.UTF_8)).build();
    appender.start();
    config.addAppender(appender);        
    
    updateLoggers(appender, config);        
}
 
開發者ID:TweetWallFX,項目名稱:TweetwallFX,代碼行數:55,代碼來源:CLogOut.java


注:本文中的org.apache.logging.log4j.core.appender.WriterAppender類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。