Application specific log in tomcat 7 using JULI?

2019-04-11 23:15发布

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

2条回答
Luminary・发光体
2楼-- · 2019-04-11 23:34

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


Arguments in the JVM

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

  1. The location of the general logging.properties for Tomcat (in the conf directory of Tomcat)
  2. 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"
查看更多
Emotional °昔
3楼-- · 2019-04-11 23:41

are you sure that you write to the correct logger , i.e. Logger.getLogger("com.xyz")?

I think that you may got wrong when you wrote in logging.properties:com.xyz.level=ALL com.xyz.handlers=org.apache.juli.FileHandler in the case that you actually write to the logger Logger.getLogger(com.xyz.YourClass.class), that because in the logging properties file you should write the logger name which is in your case com.xyz.YourClass

查看更多
登录 后发表回答