SimpleFormatter 忽略 java.util.logging.SimpleFormatter.format 属性 [英] SimpleFormatter ignoring the java.util.logging.SimpleFormatter.format property
问题描述
我在 GlassFish 4 上使用 java.util.logging.
I'm using java.util.logging on GlassFish 4.
我正在定义自己的类来通过定义 System 属性来初始化 LogManager
:-Djava.util.logging.config.class
.
I'm defining my own class to initialize the LogManager
by defining the System property:
-Djava.util.logging.config.class
.
我的班级加载 logging.properties
文件,将其与其他一些属性文件合并并进行一些自定义替换.
My class loads the logging.properties
file, merges it with some other property file and does some custom replacement.
以下是我的logging.properties
文件的相关部分:
The following is the relevant part of my logging.properties
file:
java.util.logging.FileHandler.pattern=C:/Work/server/glassfish/domains/domain1/logs/JMSFileHandler%g.log
java.util.logging.FileHandler.limit=2000000
java.util.logging.FileHandler.count=20
java.util.logging.FileHandler.append=true
java.util.logging.FileHandler.level=ALL
java.util.logging.FileHandler.formatter=java.util.logging.SimpleFormatter
java.util.logging.SimpleFormatter.format=%1$tY:%1$tm:%1$td %1$tH:%1$tM:%1$tS|%4$s: %2$s%n%5$s%n%6$s%n
我正在使用标准的 FileHandler
并将其配置为使用 SimpleFormatter
作为格式化程序.
I'm using the standard FileHandler
and configuring it to use the SimpleFormatter
as the formatter.
但是 java.util.logging.SimpleFormatter.format
字符串被完全忽略了.相反,SimpleFormatter 使用其默认格式.
But the java.util.logging.SimpleFormatter.format
String is being totally ignored. Instead SimpleFormatter uses its default format.
我哪里做错了?
推荐答案
我假设系统属性 java.util.logging.config.file
从一开始就由 GF 设置.事实并非如此.
I was assuming that the System Property java.util.logging.config.file
is set by GF from the beginning. This is not the case.
经过一番调查,我意识到 LogManager
被初始化了两次.第一次该属性不存在,第二次它存在.
After some investigation I realized that the LogManager
is initialized two times. In the first time that property doesn't exist, the second time it does.
我在第一次初始化时遇到错误,因为我依赖该属性,因此我没有正确初始化 LogManager
,导致 SimpleFormatter
使用默认格式.
I was getting an error on the first initialization because I was counting on that property, therefore I didn't initialize the LogManager
properly, causing the SimpleFormatter
to use the default format.
我通过更改代码解决了这个问题,不再依赖该系统属性.这解决了问题.
I fixed this by changing my code and no longer counting on that System property. This solved the issue.
GF 稍后仍会设置系统属性 java.util.logging.config.file
.
GF still sets the System property java.util.logging.config.file
later.
这篇关于SimpleFormatter 忽略 java.util.logging.SimpleFormatter.format 属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!