我需要获取在logging.properties中配置的catalina.out文件的路径.
有没有一种方法可以通过java检索属性“ 1catalina.org.apache.juli.FileHandler.directory”,而无需知道属性文件的路径?
解决方法:
如果我对您的理解正确,那么您想读取Tomcat logging.properties文件的属性.如您在Tomcat FAQ for Logging中所见,java.util.logging.config.file用于定义属性文件的路径.
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();
}
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上可用.
标签:logging,tomcat,tomcat6,java
来源: https://codeday.me/bug/20191201/2077302.html