Application specific log in tomcat 7 using JULI?

java, logging, tomcat

Solution

To configure JULI in the web applications you need have a `logging.properties` file in the `WEB-INF/classes` directory. If you use the default handlers, you may lose messages. You need to specify a prefix for the handler in your file.

handlers=1FILE.org.apache.juli.FileHandler, java.util.logging.ConsoleHandler
.handlers=java.util.logging.ConsoleHandler

1FILE.org.apache.juli.FileHandler.level=FINEST
1FILE.org.apache.juli.FileHandler.directory=/app-logs
1FILE.org.apache.juli.FileHandler.prefix=file-1

java.util.logging.ConsoleHandler.level=FINE
java.util.logging.ConsoleHandler.formatter=java.util.logging.SimpleFormatter

com.xyz.level=INFO
com.xyz.handlers=1FILE.org.apache.juli.FileHandler

com.abc.level=INFO
com.abc.handlers=java.util.logging.ConsoleHandler

A handler prefix (e.g. `1FILE.`) starts with a number, then has an arbitrary string, and ends with a period (.).

- See more in Logging in Tomcat

Arguments in the JVM

If you are not running the Tomcat from the `startup.sh` or `startup.bat`, you need to specify:

- The location of the general `logging.properties` for Tomcat (in the `conf` directory of Tomcat)

- The manager `org.apache.juli.ClassLoaderLogManager`. This is important because allows you to configure for each web application different loggin options. By default, a JVM process can only have a single configuration file.) ,

Similar to the next (I'm using eclipse):

-Djava.util.logging.config.file="C:\Users\Paul\workspaces\utils\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\conf\logging.properties" -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager

By default, `java.util.logging` read the file that is included in the JDK or JRE, e.g.:

"C:\Software\jdk1.7.0_17\jre\lib\logging.properties"

- Setting Tomcat Heap Size (JVM Heap) in Eclipse, for how to add arguments in the VM

Problem

I'm using java system logging in tomcat 7, but no logging statements get written to the log. I've added this file to my WEB-INF/classes. The log file "new-xyz-test" gets created (so I have at least some of the config right) but its empty - no log statements get printed to it. ``` handlers=java.util.logging.ConsoleHandler, org.apache.juli.FileHandler org.apache.juli.FileHandler.level=ALL org.apache.juli.FileHandler.directory=${catalina.base}/logs org.apache.juli.FileHandler.prefix=new-xyz-test- java.util.logging.ConsoleHandler.level=ALL java.util.logging.ConsoleHandler.formatter = java.util.logging.SimpleFormatter com.xyz.level=ALL com.xyz.handlers=org.apache.juli.FileHandler ```

Original source