org.apache.logging.log4j.core.config.Configuration.addLogger()方法的使用及代码示例

x33g5p2x  于2022-01-18 转载在 其他  
字(10.0k)|赞(0)|评价(0)|浏览(153)

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

Configuration.addLogger介绍

暂无

代码示例

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

public void setLoggerLevel(LoggerContext logContext, String loggerName, String newLevelStr) {
    Level newLevel = Level.getLevel(newLevelStr);
    Configuration configuration = logContext.getConfiguration();
    LoggerConfig loggerConfig = configuration.getLoggerConfig(loggerName);
    if (loggerConfig.getName().equalsIgnoreCase(loggerName)) {
      LOG.info("Setting {} log level to: {}", loggerConfig, newLevel);
      loggerConfig.setLevel(newLevel);
    } else {
      // create a new config. Make it additive (true) s.t. inherit parents appenders
      LoggerConfig newLoggerConfig = new LoggerConfig(loggerName, newLevel, true);
      LOG.info("Adding config for: {} with level: {}", newLoggerConfig, newLevel);
      configuration.addLogger(loggerName, newLoggerConfig);
    }
  }
}

代码示例来源:origin: Graylog2/graylog2-server

@VisibleForTesting
protected void setLoggerLevel(final String loggerName, final Level level) {
  final LoggerContext context = (LoggerContext) LogManager.getContext(false);
  final Configuration config = context.getConfiguration();
  final LoggerConfig loggerConfig = config.getLoggerConfig(loggerName);
  if(loggerName.equals(loggerConfig.getName())) {
    loggerConfig.setLevel(level);
  } else {
    final LoggerConfig newLoggerConfig = new LoggerConfig(loggerName, level, loggerConfig.isAdditive());
    newLoggerConfig.setLevel(level);
    config.addLogger(loggerName, newLoggerConfig);
  }
  context.updateLoggers();
}

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

conf.addLogger(loggerName, new LoggerConfig(loggerName, logLevel, true));
} else {
 if (LOG.isDebugEnabled()) {

代码示例来源:origin: org.springframework.boot/spring-boot

@Override
public void setLogLevel(String loggerName, LogLevel logLevel) {
  Level level = LEVELS.convertSystemToNative(logLevel);
  LoggerConfig loggerConfig = getLoggerConfig(loggerName);
  if (loggerConfig == null) {
    loggerConfig = new LoggerConfig(loggerName, level, true);
    getLoggerContext().getConfiguration().addLogger(loggerName, loggerConfig);
  }
  else {
    loggerConfig.setLevel(level);
  }
  getLoggerContext().updateLoggers();
}

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

"true", refs, null, config, null );
loggerConfig.addAppender(appender, null, null);
config.addLogger("org.apache.logging.log4j", loggerConfig);
ctx.updateLoggers();
final Logger logger = ctx.getLogger(CustomConfigurationTest.class.getName());

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

specificConfig = new LoggerConfig(className, Log4j2LevelAdjuster.this.level, true);
specificConfig.setParent(loggerConfig);
config.addLogger(className, specificConfig);
specificConfig = new LoggerConfig(category, Log4j2LevelAdjuster.this.level, true);
specificConfig.setParent(loggerConfig);
config.addLogger(category, specificConfig);

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

specificConfig = new LoggerConfig(className, Log4j2LevelAdjuster.this.level, true);
specificConfig.setParent(loggerConfig);
config.addLogger(className, specificConfig);
specificConfig = new LoggerConfig(category, Log4j2LevelAdjuster.this.level, true);
specificConfig.setParent(loggerConfig);
config.addLogger(category, specificConfig);

代码示例来源:origin: org.elasticsearch/elasticsearch

public static void removeAppender(final Logger logger, final Appender appender) {
  final LoggerContext ctx = (LoggerContext) LogManager.getContext(false);
  final Configuration config = ctx.getConfiguration();
  LoggerConfig loggerConfig = config.getLoggerConfig(logger.getName());
  if (!logger.getName().equals(loggerConfig.getName())) {
    loggerConfig = new LoggerConfig(logger.getName(), logger.getLevel(), true);
    config.addLogger(logger.getName(), loggerConfig);
  }
  loggerConfig.removeAppender(appender.getName());
  ctx.updateLoggers();
}

代码示例来源:origin: org.elasticsearch/elasticsearch

public static void addAppender(final Logger logger, final Appender appender) {
  final LoggerContext ctx = (LoggerContext) LogManager.getContext(false);
  final Configuration config = ctx.getConfiguration();
  config.addAppender(appender);
  LoggerConfig loggerConfig = config.getLoggerConfig(logger.getName());
  if (!logger.getName().equals(loggerConfig.getName())) {
    loggerConfig = new LoggerConfig(logger.getName(), logger.getLevel(), true);
    config.addLogger(logger.getName(), loggerConfig);
  }
  loggerConfig.addAppender(appender, null, null);
  ctx.updateLoggers();
}

代码示例来源:origin: mulesoft/mule

@Before
public void before() {
 context = getDefaultContext();
 testAppender = new TestAppender(TEST_APPENDER, null, null);
 context.getConfiguration().addAppender(testAppender);
 LoggerConfig loggerConfig =
   AsyncLoggerConfig.createLogger("false", LEVEL.name(), CATEGORY, "true",
                   new AppenderRef[] {AppenderRef.createAppenderRef(TEST_APPENDER, null, null)}, null,
                   context.getConfiguration(), null);
 loggerConfig.addAppender(testAppender, null, null);
 context.getConfiguration().addLogger(CATEGORY, loggerConfig);
 context.getConfiguration().start();
 context.updateLoggers();
}

代码示例来源:origin: ops4j/org.ops4j.pax.logging

private static boolean setLevel(final String loggerName, final Level level, final Configuration config) {
  boolean set;
  LoggerConfig loggerConfig = config.getLoggerConfig(loggerName);
  if (!loggerName.equals(loggerConfig.getName())) {
    // TODO Should additivity be inherited?
    loggerConfig = new LoggerConfig(loggerName, level, true);
    config.addLogger(loggerName, loggerConfig);
    loggerConfig.setLevel(level);
    set = true;
  } else {
    set = setLevel(loggerConfig, level);
  }
  return set;
}

代码示例来源:origin: Meituan-Dianping/Zebra

loggerConfig.addAppender(fileInfoAppender, Level.INFO, null);
config.addLogger("com.dianping.zebra", loggerConfig);

代码示例来源:origin: org.nuxeo.runtime/nuxeo-launcher-commons

private static boolean setLevel(final String loggerName, final Level level, final Configuration config) {
  boolean set;
  LoggerConfig loggerConfig = config.getLoggerConfig(loggerName);
  if (!loggerName.equals(loggerConfig.getName())) {
    // TODO Should additivity be inherited?
    loggerConfig = new LoggerConfig(loggerName, level, true);
    config.addLogger(loggerName, loggerConfig);
    loggerConfig.setLevel(level);
    set = true;
  } else {
    set = setLevel(loggerConfig, level);
  }
  return set;
}

代码示例来源:origin: apache/servicemix-bundles

public static void removeAppender(final Logger logger, final Appender appender) {
  final LoggerContext ctx = (LoggerContext) LogManager.getContext(false);
  final Configuration config = ctx.getConfiguration();
  LoggerConfig loggerConfig = config.getLoggerConfig(logger.getName());
  if (!logger.getName().equals(loggerConfig.getName())) {
    loggerConfig = new LoggerConfig(logger.getName(), logger.getLevel(), true);
    config.addLogger(logger.getName(), loggerConfig);
  }
  loggerConfig.removeAppender(appender.getName());
  ctx.updateLoggers();
}

代码示例来源:origin: kptfh/feign-reactive

private static LoggerConfig getLoggerConfig() {
  LoggerContext loggerContext = (LoggerContext) LogManager.getContext(false);
  Configuration configuration = loggerContext.getConfiguration();
  configuration.addLogger(LOGGER_NAME, new LoggerConfig());
  return configuration.getLoggerConfig(LOGGER_NAME);
 }
}

代码示例来源:origin: apache/servicemix-bundles

public static void addAppender(final Logger logger, final Appender appender) {
  final LoggerContext ctx = (LoggerContext) LogManager.getContext(false);
  final Configuration config = ctx.getConfiguration();
  config.addAppender(appender);
  LoggerConfig loggerConfig = config.getLoggerConfig(logger.getName());
  if (!logger.getName().equals(loggerConfig.getName())) {
    loggerConfig = new LoggerConfig(logger.getName(), logger.getLevel(), true);
    config.addLogger(logger.getName(), loggerConfig);
  }
  loggerConfig.addAppender(appender, null, null);
  ctx.updateLoggers();
}

代码示例来源:origin: vitaly-chibrikov/homework_tester

private static Logger configureLog4j() {
  LoggerContext context = (LoggerContext) LogManager.getContext();
  Configuration config = context.getConfiguration();
  PatternLayout layout = PatternLayout.createLayout("%m%n", null, null, Charset.defaultCharset(), false, false, null, null);
  Appender appender = ConsoleAppender.createAppender(layout, null, null, "CONSOLE_APPENDER", null, null);
  appender.start();
  AppenderRef ref = AppenderRef.createAppenderRef("CONSOLE_APPENDER", null, null);
  AppenderRef[] refs = new AppenderRef[]{ref};
  LoggerConfig loggerConfig = LoggerConfig.createLogger("false", Level.INFO, "CONSOLE_LOGGER", "com", refs, null, null, null);
  loggerConfig.addAppender(appender, null, null);
  config.addAppender(appender);
  config.addLogger("Main.class", loggerConfig);
  context.updateLoggers(config);
  return LogManager.getContext().getLogger("Main.class");
}

代码示例来源:origin: org.infinispan/infinispan-commons-test

public void install() {
 LoggerContext loggerContext = (LoggerContext) LogManager.getContext(false);
 Configuration config = loggerContext.getConfiguration();
 this.start();
 config.addAppender(this);
 AppenderRef ref = AppenderRef.createAppenderRef(this.getName(), level, null);
 AppenderRef[] refs = new AppenderRef[] {ref};
 LoggerConfig loggerConfig = LoggerConfig.createLogger(true, level, category, null, refs, null, config, null);
 loggerConfig.addAppender(this, null, null);
 config.addLogger(category, loggerConfig);
 loggerContext.updateLoggers();
}

代码示例来源:origin: com.strapdata.elasticsearch/elasticsearch

public static void addAppender(final Logger logger, final Appender appender) {
  final LoggerContext ctx = (LoggerContext) LogManager.getContext(false);
  final Configuration config = ctx.getConfiguration();
  config.addAppender(appender);
  LoggerConfig loggerConfig = config.getLoggerConfig(logger.getName());
  if (!logger.getName().equals(loggerConfig.getName())) {
    loggerConfig = new LoggerConfig(logger.getName(), logger.getLevel(), true);
    config.addLogger(logger.getName(), loggerConfig);
  }
  loggerConfig.addAppender(appender, null, null);
  ctx.updateLoggers();
}

代码示例来源:origin: com.strapdata.elasticsearch/elasticsearch

public static void removeAppender(final Logger logger, final Appender appender) {
  final LoggerContext ctx = (LoggerContext) LogManager.getContext(false);
  final Configuration config = ctx.getConfiguration();
  LoggerConfig loggerConfig = config.getLoggerConfig(logger.getName());
  if (!logger.getName().equals(loggerConfig.getName())) {
    loggerConfig = new LoggerConfig(logger.getName(), logger.getLevel(), true);
    config.addLogger(logger.getName(), loggerConfig);
  }
  loggerConfig.removeAppender(appender.getName());
  ctx.updateLoggers();
}

相关文章