Restricting Tomcat logging in eclipse

2019-09-03 15:35发布

Tomcat logges in eclipse everything starting with DEBUG. It doesn't log only its own properties but other stuff allow themselves to log (like:

[localhost-startStop-1] DEBUG o.s.w.c.s.StandardServletEnvironment or
[localhost-startStop-1] DEBUG o.s.c.i.s.PathMatchingResourcePatternResolver and many many others).

I want to limit tomcat logging to info or warning. I tried going into the tomcat directory and changing the log level in logging.propertie from "FINE" to "INFO" to no avail. I even tried to copy the file into eclipse and appending -Djava.util.logging.config.file=$/Servers/Tomcat v7.0 Server at localhost-config/logging.properties} -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager but that didn't help either (and of course I cleaned tomcat many times).

Also, in web.xml the only place I have the word 'log' not in comment is

<mime-mapping>
        <extension>gph</extension>
        <mime-type>application/vnd.flographit</mime-type>
</mime-mapping>

and

<mime-mapping>
        <extension>log</extension>
        <mime-type>text/plain</mime-type>
</mime-mapping>

and my log4j.xml files are configured with either INFO or WARNING, not DEBUG.

How can I limit the log to INFO or WARNING, or even just disallow unnecessary classes to log?

1条回答
女痞
2楼-- · 2019-09-03 15:55

Tomcat uses Juli logging framework, a mix of Java Util Logging and Apache Commons Logging. You can either set the level in the JRE, youre Eclipse is running with ([JRE_DIR]/lib/logging.properties), or you can define your own one, i.e. copy the former into the Tomcat directory and add this to the run configuration:

Eclipse: "Run" -> "Run Configurations" -> select Tomcat to the left -> select tab "Arguments" to the right -> add this to "VM Arguments":

-Djava.util.logging.config.file=[PATH_TO TOMCAT]\lib\logging.properties

In that file, change these lines:

.level=INFO

java.util.logging.ConsoleHandler.level = WARNING

Thats it.

查看更多
登录 后发表回答