ch.qos.logback.classic.Logger.getName()方法的使用及代码示例

x33g5p2x  于2022-01-23 转载在 其他  
字(8.8k)|赞(0)|评价(0)|浏览(187)

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

Logger.getName介绍

暂无

代码示例

代码示例来源:origin: ch.qos.logback/logback-classic

public int compare(Logger l1, Logger l2) {
  if (l1.getName().equals(l2.getName())) {
    return 0;
  }
  if (l1.getName().equals(Logger.ROOT_LOGGER_NAME)) {
    return -1;
  }
  if (l2.getName().equals(Logger.ROOT_LOGGER_NAME)) {
    return 1;
  }
  return l1.getName().compareTo(l2.getName());
}

代码示例来源:origin: ch.qos.logback/logback-classic

/**
   * After serialization, the logger instance does not know its LoggerContext.
   * The best we can do here, is to return a logger with the same name
   * returned by org.slf4j.LoggerFactory.
   * 
   * @return Logger instance with the same name
   * @throws ObjectStreamException
   */
  protected Object readResolve() throws ObjectStreamException {
    return LoggerFactory.getLogger(getName());
  }
}

代码示例来源:origin: ch.qos.logback/logback-classic

Logger getChildByName(final String childName) {
  if (childrenList == null) {
    return null;
  } else {
    int len = this.childrenList.size();
    for (int i = 0; i < len; i++) {
      final Logger childLogger_i = (Logger) childrenList.get(i);
      final String childName_i = childLogger_i.getName();
      if (childName.equals(childName_i)) {
        return childLogger_i;
      }
    }
    // no child found
    return null;
  }
}

代码示例来源:origin: ch.qos.logback/logback-classic

public List<String> getLoggerList() {
  LoggerContext lc = (LoggerContext) context;
  List<String> strList = new ArrayList<String>();
  Iterator<Logger> it = lc.getLoggerList().iterator();
  while (it.hasNext()) {
    Logger log = it.next();
    strList.add(log.getName());
  }
  return strList;
}

代码示例来源:origin: ch.qos.logback/logback-classic

static public java.util.logging.Logger asJULLogger(Logger logger) {
  return asJULLogger(logger.getName());
}

代码示例来源:origin: ch.qos.logback/logback-classic

public void begin(InterpretationContext ec, String name, Attributes attributes) {
  Object o = ec.peekObject();
  if (!(o instanceof Logger)) {
    inError = true;
    addError("For element <level>, could not find a logger at the top of execution stack.");
    return;
  }
  Logger l = (Logger) o;
  String loggerName = l.getName();
  String levelStr = ec.subst(attributes.getValue(ActionConst.VALUE_ATTR));
  // addInfo("Encapsulating logger name is [" + loggerName
  // + "], level value is  [" + levelStr + "].");
  if (ActionConst.INHERITED.equalsIgnoreCase(levelStr) || ActionConst.NULL.equalsIgnoreCase(levelStr)) {
    l.setLevel(null);
  } else {
    l.setLevel(Level.toLevel(levelStr, Level.DEBUG));
  }
  addInfo(loggerName + " level set to " + l.getLevel());
}

代码示例来源:origin: bwssytems/ha-bridge

private void loadLoggers() {
  this.configuredLoggers.clear();
  
  final List<Logger> loggers = LoggingUtil.getLoggers(this.showAll);
  
  for (Logger logger : loggers) {
    
    this.configuredLoggers.add(new LoggerInfo(logger.getName(), logger.getEffectiveLevel().levelInt));
  }
}

代码示例来源:origin: ch.qos.logback/logback-classic

final void noAppenderDefinedWarning(final Logger logger) {
  if (noAppenderWarning++ == 0) {
    getStatusManager().add(new WarnStatus("No appenders present in context [" + getName() + "] for logger [" + logger.getName() + "].", logger));
  }
}

代码示例来源:origin: alibaba/nacos

public static Map<String, LoggerInfo> getLoggers(String name) {
  Map<String, LoggerInfo> appenders = new HashMap<String, LoggerInfo>(10);
  if (Logback) {
    LoggerContext loggerContext = (LoggerContext)lcObject;
    if (name != null && !"".equals(name.trim())) {
      Logger logger = loggerContext.exists(name);
      if (logger != null) {
        appenders.put(name, doGetLoggerInfo(logger));
      }
    } else {
      // 获取所有logger时,如果没有appender则忽略
      List<Logger> loggers = loggerContext.getLoggerList();
      for (Logger logger : loggers) {
        LoggerInfo info = doGetLoggerInfo(logger);
        if (info.getAppenders() == null || !info.getAppenders().isEmpty()) {
          appenders.put(logger.getName(), info);
        }
      }
    }
  }
  return appenders;
}

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

private LoggerConfiguration getLoggerConfiguration(
    ch.qos.logback.classic.Logger logger) {
  if (logger == null) {
    return null;
  }
  LogLevel level = LEVELS.convertNativeToSystem(logger.getLevel());
  LogLevel effectiveLevel = LEVELS
      .convertNativeToSystem(logger.getEffectiveLevel());
  String name = logger.getName();
  if (!StringUtils.hasLength(name) || Logger.ROOT_LOGGER_NAME.equals(name)) {
    name = ROOT_LOGGER_NAME;
  }
  return new LoggerConfiguration(name, level, effectiveLevel);
}

代码示例来源:origin: alibaba/nacos

@Override
public void activateAsync(List<Object[]> args) {
  AsyncAppender asynAppender = new AsyncAppender();
  invokeMethod(asynAppender, args);
  asynAppender.setName(productName + "." + logger.getName() + ".AsyncAppender");
  asynAppender.setContext(LogbackLoggerContextUtil.getLoggerContext());
  Iterator<Appender<ILoggingEvent>> iterator = logger.iteratorForAppenders();
  boolean hasAppender = false;
  while (iterator.hasNext()) {
    hasAppender = true;
    asynAppender.addAppender(iterator.next());
  }
  if (!hasAppender) {
    throw new IllegalStateException("Activate async appender failed, no appender exist.");
  }
  asynAppender.start();
  iterator = logger.iteratorForAppenders();
  while (iterator.hasNext()) {
    logger.detachAppender(iterator.next());
  }
  logger.addAppender(asynAppender);
  setProductName(productName);
}

代码示例来源:origin: ch.qos.logback/logback-classic

public LoggingEvent(String fqcn, Logger logger, Level level, String message, Throwable throwable, Object[] argArray) {
  this.fqnOfLoggerClass = fqcn;
  this.loggerName = logger.getName();
  this.loggerContext = logger.getLoggerContext();
  this.loggerContextVO = loggerContext.getLoggerContextRemoteView();
  this.level = level;
  this.message = message;
  this.argumentArray = argArray;
  if (throwable == null) {
    throwable = extractThrowableAnRearrangeArguments(argArray);
  }
  if (throwable != null) {
    this.throwableProxy = new ThrowableProxy(throwable);
    LoggerContext lc = logger.getLoggerContext();
    if (lc.isPackagingDataEnabled()) {
      this.throwableProxy.calculatePackagingData();
    }
  }
  timeStamp = System.currentTimeMillis();
}

代码示例来源:origin: SonarSource/sonarqube

@Test
public void root_logger_writes_to_console_with_formatting_and_to_sonar_log_file_when_running_from_ITs() {
 emulateRunFromCommandLine(true);
 LoggerContext ctx = underTest.configure();
 Logger rootLogger = ctx.getLogger(ROOT_LOGGER_NAME);
 verifyAppConsoleAppender(rootLogger.getAppender("APP_CONSOLE"));
 verifySonarLogFileAppender(rootLogger.getAppender("file_sonar"));
 assertThat(rootLogger.iteratorForAppenders()).hasSize(2);
 ctx.getLoggerList()
  .stream()
  .filter(logger -> !ROOT_LOGGER_NAME.equals(logger.getName()))
  .forEach(AppLoggingTest::verifyNoFileAppender);
}

代码示例来源:origin: SonarSource/sonarqube

@Test
public void root_logger_writes_to_console_with_formatting_and_to_sonar_log_file_when_running_from_command_line() {
 emulateRunFromCommandLine(false);
 LoggerContext ctx = underTest.configure();
 Logger rootLogger = ctx.getLogger(ROOT_LOGGER_NAME);
 verifyAppConsoleAppender(rootLogger.getAppender("APP_CONSOLE"));
 verifySonarLogFileAppender(rootLogger.getAppender("file_sonar"));
 assertThat(rootLogger.iteratorForAppenders()).hasSize(2);
 // verify no other logger writes to sonar.log
 ctx.getLoggerList()
  .stream()
  .filter(logger -> !ROOT_LOGGER_NAME.equals(logger.getName()))
  .forEach(AppLoggingTest::verifyNoFileAppender);
}

代码示例来源:origin: alibaba/nacos

private static LoggerInfo doGetLoggerInfo(Logger logger) {
  LoggerInfo info = new LoggerInfo(logger.getName(), logger.isAdditive());
  Level level = logger.getLevel(), effectiveLevel = logger.getEffectiveLevel();
  if (level != null) {
    info.setLevel(level.toString());
  }
  if (effectiveLevel != null) {
    info.setEffectiveLevel(effectiveLevel.toString());
  }
  List<AppenderInfo> result = doGetLoggerAppenders(logger.iteratorForAppenders());
  info.setAppenders(result);
  return info;
}

代码示例来源:origin: camunda/camunda-bpm-platform

public int compare(Logger l1, Logger l2) {
 if (l1.getName().equals(l2.getName())) {
  return 0;
 }
 if (l1.getName().equals(Logger.ROOT_LOGGER_NAME)) {
  return -1;
 }
 if (l2.getName().equals(Logger.ROOT_LOGGER_NAME)) {
  return 1;
 }
 return l1.getName().compareTo(l2.getName());
}

代码示例来源:origin: camunda/camunda-bpm-platform

/**
  * After serialization, the logger instance does not know its LoggerContext.
  * The best we can do here, is to return a logger with the same name
  * returned by org.slf4j.LoggerFactory.
  * 
  * @return Logger instance with the same name
  * @throws ObjectStreamException
  */
 protected Object readResolve() throws ObjectStreamException {
  return LoggerFactory.getLogger(getName());
 }
}

代码示例来源:origin: camunda/camunda-bpm-platform

public List<String> getLoggerList() {
 LoggerContext lc = (LoggerContext) context;
 List<String> strList = new ArrayList<String>();
 Iterator<Logger> it = lc.getLoggerList().iterator();
 while (it.hasNext()) {
  Logger log = it.next();
  strList.add(log.getName());
 }
 return strList;
}

代码示例来源:origin: camunda/camunda-bpm-platform

static public java.util.logging.Logger asJULLogger(Logger logger) {
 return asJULLogger(logger.getName());
}

代码示例来源:origin: camunda/camunda-bpm-platform

final void noAppenderDefinedWarning(final Logger logger) {
 if (noAppenderWarning++ == 0) {
  getStatusManager().add(
      new WarnStatus("No appenders present in context [" + getName()
          + "] for logger [" + logger.getName() + "].", logger));
 }
}

相关文章