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

标签 java tomcat logging tomcat6

我需要获取在 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/

相关文章:

c# - 登录 C# : Getting the class/method name performance

logging - 如何避免在Linux内核中丢失printk日志

java - Android + Dozer 抛出 IllegalArgumentException

java - 以编程方式创建复合过滤器以在 log4j 2 中定义多个过滤器

java - 如何将 spring boot 参数传递给 tomcat 部署?

java - Spring Boot或者Tomcat缓存静态资源,每次刷新都得重新构建

java - 使用多维字符数组?

Java - 在mybatis 3中设置参数的jdbcType

java - 无法启动组件 [StandardEngine[Catalina].StandardHost[localhost]

java - 未在 linux/EC2 实例中创建日志文件