gpt4 book ai didi

java - 如何在 java 程序中检索 catalina.out 的路径?

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:56:26 25 4
gpt4 key购买 nike

我需要获取在 logging.properties 中配置的 catalina.out 文件的路径。

有没有办法在不知道属性文件路径的情况下通过 java 检索属性“1catalina.org.apache.juli.FileHandler.directory”?

最佳答案

如果我没理解错的话,您想要读取 Tomcat logging.properties 文件的一个属性。正如您在 Tomcat FAQ for Logging 中看到的那样, java.util.logging.config.file 用于定义属性文件的路径。

然后您可以通过 Java System Properties 检索此路径:

String pathLogProps = System.getProperty("java.util.logging.config.file");
Properties properties = new Properties();
try {
properties.load(new FileInputStream(pathLogProps));
System.out.println(prop.getProperty("database"));
} catch (IOException ex) {
ex.printStackTrace();
}

如果未设置,我将遵循 Apache Tomcat 7 Logging Documentation 中的提示:

JULI is enabled by default, and supports per classloader configuration, in addition to the regular global java.util.logging configuration. This means that logging can be configured at the following layers:

  • Globally. That is usually done in the ${catalina.base}/conf/logging.properties file. The file is specified by the java.util.logging.config.file System property which is set by the startup scripts.
  • If it is not readable or is not configured, the default is to use the ${java.home}/lib/logging.properties file in the JRE. In the web application. The file will be WEB-INF/classes/logging.properties

默认情况下,logging.properties 文件的路径应该在环境变量 catalina.base 上可用,分别为 CATALINA_BASE

关于java - 如何在 java 程序中检索 catalina.out 的路径?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11773919/

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