Tomcat下修改java.util.logging.SimpleFormatter格式属性 [英] Modifying java.util.logging.SimpleFormatter format property under Tomcat

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

问题描述

我正在使用 Tomcat 7.0.28,在 Ubuntu 上的 OpenJDK 1.7 下运行,并且正在尝试修改 java.util.logging.SimpleFormatter 使用的格式字符串.根据该类的 Javadocs,我可以指定属性 java.util.logging.SimpleFormatter.format 来更改格式.事实上,当我在 Eclipse 中运行我的 web 应用程序并在我的 logging.properties 文件中更改此属性时,它可以工作.

I am using Tomcat 7.0.28, running under OpenJDK 1.7 on Ubuntu, and am trying to modify the formatting string used by java.util.logging.SimpleFormatter. According to the Javadocs for that class, I can specify the property java.util.logging.SimpleFormatter.format to change the format. And indeed, when I run my webapp in Eclipse and change this property in my logging.properties file, it works.

但是,当我将应用程序部署到 Tomcat 时,该属性似乎没有任何影响.我确信我的属性文件被正确读取,因为我对其所做的其他更改确实生效(我正在使用

However, when I deploy the app to Tomcat, this property does not seem to have any effect. I am confident that my properties file is being read correctly, as other changes that I make to it do indeed take effect (I'm reading the properties in from a file using

LogManager.getLogManager().readConfiguration(new FileInputStream(file))

文件是通过我的 web.xml 文件中的参数配置的.我试过将文件放在 WEB-INF/classes/logging.properties 中,行为没有改变.

where file is configured via a parameter in my web.xml file. I've tried putting the file in WEB-INF/classes/logging.properties, with no change in behavior.

SimpleFormatter 的 Javadoc 指定,如果属性文件和系统属性都指定了格式字符串,则系统属性优先.我已验证未设置系统属性

The Javadocs for SimpleFormatter specify that if both a properties file and a system property specify the formatting string, the system property takes precedence. I have verified that the system property is not set

context.log ("Formatting system property is " + System.getProperty("java.util.logging.SimpleFormatter.format"));

在 ServletContextListener.contextInitialized 方法中.

in a ServletContextListener.contextInitialized method.

这是我的完整日志属性文件

Here's my logging properties file in full

handlers=java.util.logging.ConsoleHandler

#  Default logging level for root logger
.level=FINE

#  Set the level for the ConsoleHandler
java.util.logging.ConsoleHandler.level=FINE
java.util.logging.ConsoleHandler.formatter=java.util.logging.SimpleFormatter
java.util.logging.SimpleFormatter.format=[%1$tF %1$tr] %3$s %4$s:  %5$s %n

我已经尝试了所有我能想到的方法,包括修改 TOMCAT/conf 和 JRE_HOME/lib 目录中的 logging.properties.似乎没什么区别.

I've tried everything I can think of, including modifying logging.properties in both the TOMCAT/conf and JRE_HOME/lib directory. Nothing seems to make any difference.

推荐答案

感谢 错误报告中的信息 由 nolan6000 指出,我终于用 tomcat-juli 完成了这个工作.

Thanks to info in the bug report pointed out by nolan6000 I finally got this working with tomcat-juli.

代替:

java.util.logging.SimpleFormatter.format=%4$s: %5$s [%1$tc]%n

必须是:

1catalina.java.util.logging.SimpleFormatter.format=%4$s: %5$s [%1$tc]%n

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

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