当前位置: 首页>>代码示例>>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;未经允许,请勿转载。