我使用(RAD)创建了一个动态web项目。我使用java.util.logging作为日志记录框架。我直接将logging.properties放在WEB/类中。
我面临的问题是,即使我将logging.properties放在WEB/类中,应用程序也无法加载它。我在WebSphere应用服务器管理员控制台中添加了以下通用JVM参数
-Djava.util.logging.config.file="logging.properties"我在servlet init方法中添加了以下代码片段。
Properties prop = System.getProperties();
prop.setProperty("java.util.logging.config.file", "logging.properties");
System.out.println("Is file exists " + file.exists());
try {
LogManager.getLogManager().readConfiguration();
} catch (IOException ex) {
ex.printStackTrace();
}我在logging.properties中关闭了控制台级别的调试,所以我不应该在控制台中获得日志记录。但目前,我正在控制台中获取日志,而不是在logging.properits中提到的日志文件中。
logging.properties
#------------------------------------------
# Handlers
#-----------------------------------------
handlers=java.util.logging.ConsoleHandler,java.util.logging.FileHandler
# Default global logging level
.level=ALL
# ConsoleHandler
java.util.logging.ConsoleHandler.level=OFF
java.util.logging.ConsoleHandler.formatter=java.util.logging.SimpleFormatter
# FileHandler
java.util.logging.FileHandler.level=FINE
# Naming style for the output file:
java.util.logging.FileHandler.pattern=${SERVER_LOG_ROOT}/nyllogs/loadData.log
# Name of the character set encoding to use
java.util.logging.FileHandler.encoding=UTF8
# Limiting size of output file in bytes:
java.util.logging.FileHandler.limit=25000000
# Number of output files to cycle through
java.util.logging.FileHandler.count=2
# Style of output (Simple or XML):
java.util.logging.FileHandler.formatter=java.util.logging.SimpleFormatter请让我知道为什么应用程序不能拿起logging.properties文件?
发布于 2013-04-11 06:39:34
使用readConfiguration(is)从输入流读取配置。您的代码设置了一个具有相对路径的属性,但是JVM无法查看它。
Properties prop = System.getProperties();
prop.setProperty("java.util.logging.config.file", "logging.properties");调用不带参数的readConfiguration()方法只会重新加载属性,因为路径是相对的,因此可能不会加载这些属性。
public void readConfiguration()
throws IOException,SecurityException
Reinitialize the logging properties and reread the logging configuration.对属性使用绝对路径或传递Inputstream。这里是一个从文件加载属性的示例,并使用一个InputStream。
发布于 2013-04-11 16:53:11
在WebSphere服务器中,您要做的事情不仅会改变应用程序的日志记录配置,还会改变整个服务器的日志配置。由于WebSphere本身使用java.util.logging,这意味着WebSphere在内部记录的所有内容都与应用程序日志相同。这是没有意义的,因为这样您就可以使用标准的WebSphere日志文件(SystemOut.log和trace.log)。
此外,由于WebSphere安装了自己的LogHandler,很可能它将禁止使用readConfiguration()方法。
https://stackoverflow.com/questions/15942061
复制相似问题