gpt4 book ai didi

org.apache.logging.log4j.core.appender.WriterAppender.createAppender()方法的使用及代码示例

转载 作者:知者 更新时间:2024-03-26 12:33:05 26 4
gpt4 key购买 nike

本文整理了Java中org.apache.logging.log4j.core.appender.WriterAppender.createAppender()方法的一些代码示例,展示了WriterAppender.createAppender()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。WriterAppender.createAppender()方法的具体详情如下:
包路径:org.apache.logging.log4j.core.appender.WriterAppender
类名称:WriterAppender
方法名:createAppender

WriterAppender.createAppender介绍

[英]Creates a WriterAppender.
[中]创建WriterAppender。

代码示例

代码示例来源:origin: spring-projects/spring-batch

@Override
protected void setUp() throws Exception {
  super.setUp();
  Logger logger = LoggerFactory.getLogger(LogOrRethrowExceptionHandler.class);
  writer = new StringWriter();
  LoggerContext loggerContext = (LoggerContext) LogManager.getContext();
  Configuration configuration = loggerContext.getConfiguration();
  LoggerConfig rootLoggerConfig = configuration.getLoggerConfig(logger.getName());
  rootLoggerConfig.getAppenders().forEach((name, appender) -> {
    rootLoggerConfig.removeAppender(name);
  });
  Appender appender = WriterAppender.createAppender(PatternLayout.createDefaultLayout(), null, writer,"TESTWriter", false, false);
  rootLoggerConfig.addAppender(appender, org.apache.logging.log4j.Level.DEBUG, null);
}

代码示例来源:origin: igniterealtime/Openfire

String addAppender(final Writer writer) {
  final String name = "openfire-s2s-test-appender-" + StringUtils.randomString( 10 );
  final LoggerContext context = LoggerContext.getContext(false);
  final Configuration config = context.getConfiguration();
  final PatternLayout layout = PatternLayout.createDefaultLayout(config);
  final Appender appender = WriterAppender.createAppender(layout, null, writer, name, false, true);
  appender.start();
  config.addAppender(appender);
  final Level level = null;
  final Filter filter = null;
  for (final LoggerConfig loggerConfig : config.getLoggers().values()) {
    loggerConfig.addAppender(appender, level, filter);
  }
  config.getRootLogger().addAppender(appender, level, filter);
  return name;
}

代码示例来源:origin: org.apache.logging.log4j/log4j-core

private void addAppender(final Writer writer, final String writerName) {
  final LoggerContext context = LoggerContext.getContext(false);
  final Configuration config = context.getConfiguration();
  final PatternLayout layout = PatternLayout.createDefaultLayout(config);
  final Appender appender = WriterAppender.createAppender(layout, null, writer, writerName, false, true);
  appender.start();
  config.addAppender(appender);
  ConfigurationTestUtils.updateLoggers(appender, config);
}

代码示例来源:origin: apache/asterixdb

public static void start() {
  final LoggerContext context = LoggerContext.getContext(false);
  final Appender appender = WriterAppender.createAppender(null, null, new LogWriter(), "MEMORY", false, true);
  appender.start();
  final Configuration config = context.getConfiguration();
  config.addAppender(appender);
  for (final LoggerConfig loggerConfig : config.getLoggers().values()) {
    loggerConfig.addAppender(appender, null, null);
  }
  config.getRootLogger().addAppender(appender, Level.ALL, null);
  context.updateLoggers();
}

代码示例来源:origin: FINRAOS/herd

@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;
}

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com