gpt4 book ai didi

tomcat - Tomcat下修改java.util.logging.SimpleFormatter格式属性

转载 作者:行者123 更新时间:2023-11-28 21:44:43 25 4
gpt4 key购买 nike

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

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

从文件中读取属性
LogManager.getLogManager().readConfiguration(new FileInputStream(file))

其中文件是通过我的 web.xml 文件中的参数配置的。我已尝试将文件放在 WEB-INF/classes/logging.properties 中,但行为没有任何变化。

SimpleFormatter 的 Javadocs 指定如果属性文件和系统属性都指定格式字符串,则系统属性优先。我已确认未设置系统属性

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

在 ServletContextListener.contextInitialized 方法中。

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

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。似乎没有任何区别。

最佳答案

感谢 the bug report 中的信息nolan6000 指出,我终于可以使用 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 - Tomcat下修改java.util.logging.SimpleFormatter格式属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11308633/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com