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

x33g5p2x  于2022-01-29 转载在 其他  
字(8.5k)|赞(0)|评价(0)|浏览(139)

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

RollingFileAppender.getFileName介绍

[英]Returns the File name for the Appender.
[中]返回追加器的文件名。

代码示例

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

/**
 * Given an appender name, as configured, get the parent directory of the appender's log file.
 * Note that if anything goes wrong, this will throw an Error and exit.
 */
private String logRootDir(String appenderName) {
  Appender appender = ((LoggerContext) LogManager.getContext()).getConfiguration().getAppender(appenderName);
  if (appenderName != null && appender != null && RollingFileAppender.class.isInstance(appender)) {
    return new File(((RollingFileAppender) appender).getFileName()).getParent();
  } else {
    throw new RuntimeException("Log viewer could not find configured appender, or the appender is not a FileAppender. "
        + "Please check that the appender name configured in storm and log4j agree.");
  }
}

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

public void localJobDebugger(int exitVal, String taskId) {
 StringBuilder sb = new StringBuilder();
 sb.append("\n");
 sb.append("Task failed!\n");
 sb.append("Task ID:\n  " + taskId + "\n\n");
 sb.append("Logs:\n");
 console.printError(sb.toString());
 for (Appender appender : ((Logger) LogManager.getRootLogger()).getAppenders().values()) {
  if (appender instanceof FileAppender) {
   console.printError(((FileAppender) appender).getFileName());
  } else if (appender instanceof RollingFileAppender) {
   console.printError(((RollingFileAppender) appender).getFileName());
  }
 }
}

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

/** {@inheritDoc} */
@Nullable @Override public String fileName() {
  for (Logger log = impl; log != null; log = log.getParent()) {
    for (Appender a : log.getAppenders().values()) {
      if (a instanceof FileAppender)
        return ((FileAppender)a).getFileName();
      if (a instanceof RollingFileAppender)
        return ((RollingFileAppender)a).getFileName();
      if (a instanceof RoutingAppender) {
        try {
          RoutingAppender routing = (RoutingAppender)a;
          Field appsFiled = routing.getClass().getDeclaredField("appenders");
          appsFiled.setAccessible(true);
          Map<String, AppenderControl> appenders = (Map<String, AppenderControl>)appsFiled.get(routing);
          for (AppenderControl control : appenders.values()) {
            Appender innerApp = control.getAppender();
            if (innerApp instanceof FileAppender)
              return normalize(((FileAppender)innerApp).getFileName());
            if (innerApp instanceof RollingFileAppender)
              return normalize(((RollingFileAppender)innerApp).getFileName());
          }
        }
        catch (IllegalAccessException | NoSuchFieldException e) {
          error("Failed to get file name (was the implementation of log4j2 changed?).", e);
        }
      }
    }
  }
  return null;
}

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

/**
 * Get path of the log file for user to see on the WebUI.
 */
public static String getLogFilePath() {
 String logFilePath = null;
 org.apache.logging.log4j.Logger rootLogger = LogManager.getRootLogger();
 if (rootLogger instanceof org.apache.logging.log4j.core.Logger) {
  org.apache.logging.log4j.core.Logger coreLogger =
    (org.apache.logging.log4j.core.Logger)rootLogger;
  for (Appender appender : coreLogger.getAppenders().values()) {
   if (appender instanceof FileAppender) {
    logFilePath = ((FileAppender) appender).getFileName();
   } else if (appender instanceof RollingFileAppender) {
    logFilePath = ((RollingFileAppender) appender).getFileName();
   } else if (appender instanceof RollingRandomAccessFileAppender) {
    logFilePath = ((RollingRandomAccessFileAppender) appender).getFileName();
   }
  }
 }
 return logFilePath;
}

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

console.printInfo("Execution log at: " + ((FileAppender) appender).getFileName());
} else if (appender instanceof RollingFileAppender) {
 console.printInfo("Execution log at: " + ((RollingFileAppender) appender).getFileName());

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

console.printInfo("Execution log at: " + ((FileAppender) appender).getFileName());
} else if (appender instanceof RollingFileAppender) {
 console.printInfo("Execution log at: " + ((RollingFileAppender) appender).getFileName());

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

console.printInfo("Execution log at: " + ((FileAppender) appender).getFileName());
} else if (appender instanceof RollingFileAppender) {
 console.printInfo("Execution log at: " + ((RollingFileAppender) appender).getFileName());

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

@Test
  public void testHostname() {
    final org.apache.logging.log4j.Logger testLogger = context.getLogger("org.apache.logging.log4j.hosttest");
    testLogger.debug("Hello, {}", "World");
    final List<String> msgs = host.getMessages();
    assertThat(msgs, hasSize(1));
    String expected = NetUtils.getLocalHostname() + Strings.LINE_SEPARATOR;
    assertThat(msgs.get(0), endsWith(expected));
    assertNotNull("No Host FileAppender file name", hostFile.getFileName());
    expected = "target/" + NetUtils.getLocalHostname() + ".log";
    String name = hostFile.getFileName();
    assertEquals("Incorrect HostFile FileAppender file name - expected " + expected + " actual - " + name, name,
      expected);
    name = hostFile.getFilePattern();
    assertNotNull("No file pattern", name);
    expected = "target/" + NetUtils.getLocalHostname() + "-%d{MM-dd-yyyy}-%i.log";
    assertEquals("Incorrect HostFile FileAppender file pattern - expected " + expected + " actual - " + name, name,
      expected);

  }
}

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

/**
 * Returns list of files produced by {@link FileAppender}s defined in a given {@link Configuration}. There's no
 * need for the log4j configuration corresponding to this repository of being active.
 *
 * @param configuration the {@link Configuration} to browse looking for {@link FileAppender}
 * @return {@link FileAppender}s present in configuration
 * @since 10.3
 */
public static List<String> getFileAppendersFileNames(Configuration configuration) {
  List<String> names = new ArrayList<>();
  for (Appender appender : configuration.getAppenders().values()) {
    if (appender instanceof FileAppender) {
      names.add(((FileAppender) appender).getFileName());
    } else if (appender instanceof RollingFileAppender) {
      names.add(((RollingFileAppender) appender).getFileName());
    }
  }
  return names;
}

代码示例来源:origin: org.apache.ignite/ignite-log4j2

/** {@inheritDoc} */
@Nullable @Override public String fileName() {
  for (Logger log = impl; log != null; log = log.getParent()) {
    for (Appender a : log.getAppenders().values()) {
      if (a instanceof FileAppender)
        return ((FileAppender)a).getFileName();
      if (a instanceof RollingFileAppender)
        return ((RollingFileAppender)a).getFileName();
      if (a instanceof RoutingAppender) {
        try {
          RoutingAppender routing = (RoutingAppender)a;
          Field appsFiled = routing.getClass().getDeclaredField("appenders");
          appsFiled.setAccessible(true);
          Map<String, AppenderControl> appenders = (Map<String, AppenderControl>)appsFiled.get(routing);
          for (AppenderControl control : appenders.values()) {
            Appender innerApp = control.getAppender();
            if (innerApp instanceof FileAppender)
              return normalize(((FileAppender)innerApp).getFileName());
            if (innerApp instanceof RollingFileAppender)
              return normalize(((RollingFileAppender)innerApp).getFileName());
          }
        }
        catch (IllegalAccessException | NoSuchFieldException e) {
          error("Failed to get file name (was the implementation of log4j2 changed?).", e);
        }
      }
    }
  }
  return null;
}

代码示例来源:origin: bioinformatics-ua/dicoogle

protected String logFilename() {
  if (this.logFilename == null) {
    org.apache.logging.log4j.Logger logger = LogManager.getLogger();
    Map<String, Appender> appenderMap = ((org.apache.logging.log4j.core.Logger) logger).getAppenders();
    for (Map.Entry<String,Appender> e : appenderMap.entrySet()) {
      String filename = null;
      Appender appender = e.getValue();
      if (appender instanceof FileAppender) {
        filename = ((FileAppender)appender).getFileName();
      } else if (appender instanceof RollingFileAppender) {
        filename = ((RollingFileAppender)appender).getFileName();
      } else if (appender instanceof RandomAccessFileAppender) {
        filename = ((RandomAccessFileAppender)appender).getFileName();
      } else if (appender instanceof RollingRandomAccessFileAppender) {
        filename = ((RollingRandomAccessFileAppender)appender).getFileName();
      }
      if (filename != null) {
        classLogger.debug("Using \"{}\" as the file for the server log.", filename);
        this.logFilename = filename;
        return this.logFilename;
      }
    }
    // no file appender found, use default DICOMLOG.log
    classLogger.debug("No file appender found, using \"DICOMLOG.log\" as the default logger");
    this.logFilename = Platform.homePath() + "DICOMLOG.log";
  }
  return this.logFilename;
}

代码示例来源:origin: org.apereo.cas/cas-server-core-logging

builder.append(FILE_PARAM, ((RollingFileAppender) appender).getFileName());
builder.append(FILE_PATTERN_PARAM, ((RollingFileAppender) appender).getFilePattern());

相关文章