Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Modifying java.util.logging.SimpleFormatter format property under Tomcat

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.

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))

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.

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"));

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

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.

like image 850
ryanmcfall Avatar asked Jul 03 '12 10:07

ryanmcfall


People also ask

What is the name of Java logging method used in Tomcat?

As of Tomcat 5.5, Apache's Java Commons Logging (JCL) technology is used throughout Tomcat. JCL is a lightweight API for Java applications that allows hierarchical logging to be supported across all log levels, independent of logging implementation.

Where do I put logging properties file?

properties from the classpath. Normally, we put the logging. properties at the src/main/resources , and project compile or build will copy it to the root of the classpath. And we can use LogManager or System.

What is the default log level in Apache Tomcat?

The default logging level is INFO , and apart from the loggers mentioned in the Facility specific properties section, all loggers will have that level. See the Tomcat 6/Tomcat 7 logging documentation for more information. The example logging.


1 Answers

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

Instead of:

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

it has to be:

1catalina.java.util.logging.SimpleFormatter.format=%4$s: %5$s [%1$tc]%n
like image 92
rhinmass Avatar answered Sep 22 '22 22:09

rhinmass