繁体   English   中英

使用Websphere的java.util.logging

[英]java.util.logging with Websphere

我使用IBM Rational Application Developer(RAD)创建了一个动态Web项目。 我使用java.util.logging作为日志框架。 我将logging.properties直接放在WEB-INF / classes中。

我面临的问题是,即使我把它放在WEB-INF / classes中,应用程序也无法加载logging.properties。 我在WebSphere Application Server管理员控制台中添加了以下通用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文件?

在WebSphere服务器中,您尝试执行的操作的效果是不仅更改应用程序的日志记录配置,还更改整个服务器的日志记录配置。 由于WebSphere本身使用java.util.logging,这意味着WebSphere内部记录的所有内容都与应用程序日志一起发送到同一文件。 这将毫无意义,因为您可以使用标准的WebSphere日志文件( SystemOut.logtrace.log )。

此外,由于WebSphere安装了自己的LogHandler ,因此很可能禁止使用readConfiguration()方法。

使用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示例

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM