SimpleFormatter忽略java.util.logging.SimpleFormatter.format属性 [英] SimpleFormatter ignoring the java.util.logging.SimpleFormatter.format property

查看:176
本文介绍了SimpleFormatter忽略java.util.logging.SimpleFormatter.format属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我定义了自己的类来初始化 LogManager

code>通过定义系统属性:
-Djava.util.logging.config.class



My class加载 logging.properties 文件,将它与其他一些属性文件合并并进行一些自定义替换。



以下是我的 logging.properties 文件的相关部分:

  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 作为格式化程序。 / p>

但是 java.util.logging.SimpleFormatter.format 字符串被完全忽略。


$ b

我假定系统属性 java.util.logging.config.file 由GF从一开始就设置。事实并非如此。



经过一番调查后,我意识到 LogManager 被初始化了两次。这是财产第一次不存在,第二次。



我在第一次初始化时收到一个错误,因为我指望这个属性,因此我没有初始化 LogManager ,导致 SimpleFormatter 使用默认格式。



我通过更改代码和不再依赖该系统属性。这解决了这个问题。

GF后来还设置了系统属性 java.util.logging.config.file

I'm using java.util.logging on GlassFish 4.

I'm defining my own class to initialize the LogManager by defining the System property: -Djava.util.logging.config.class.

My class loads the logging.properties file, merges it with some other property file and does some custom replacement.

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

I'm using the standard FileHandler and configuring it to use the SimpleFormatter as the formatter.

But the java.util.logging.SimpleFormatter.format String is being totally ignored. Instead SimpleFormatter uses its default format.

Where did I go wrong?

解决方案

I was assuming that the System Property java.util.logging.config.file is set by GF from the beginning. This is not the case.

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.

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 still sets the System property java.util.logging.config.file later.

这篇关于SimpleFormatter忽略java.util.logging.SimpleFormatter.format属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆