'Spring Boot: How to disable Tomcat startup logging?
I'm using Spring Boot 2.0.x with Logback. On startup of my application (using an embedded tomcat), I see several INFORMATION log messages (written to standard error) which apparently originate directly from the embedded tomcat.
In contrast to the rest of all my logging, these messages seem to not be written by Logback. The messages have the following content:
Jan 08, 2019 3:13:00 PM org.apache.coyote.AbstractProtocol init
INFORMATION: Initializing ProtocolHandler ["http-nio-8080"]
Jan 08, 2019 3:13:00 PM org.apache.catalina.core.StandardService startInternal
INFORMATION: Starting service [Tomcat]
Jan 08, 2019 3:13:00 PM org.apache.catalina.core.StandardEngine startInternal
INFORMATION: Starting Servlet Engine: Apache Tomcat/8.5.34
Jan 08, 2019 3:13:01 PM org.apache.catalina.core.ApplicationContext log
INFORMATION: Initializing Spring embedded WebApplicationContext
I'm not interested in any of this, it's just noise. How do I get rid of those logs? I tried all sorts of solutions, but nothing worked so far.
Solution 1:[1]
Okay, it took me about 5 hours to figure this out:
- Tomcat uses
JULI, a derivative ofjava.util.logging - JULI itself is compatible with
java.util.logging, so you can configure it the same way - When starting up, the embedded tomcat will not care about any of your logging settings (at least it did not for me)
The up-shot is: before I start my spring-embedded tomcat, I had to do this:
java.util.logging.Logger.getLogger("org.apache").setLevel(java.util.logging.Level.WARNING);
This will instruct java.util.logging (implemented by JULI) to only propagate warnings to the console. This eliminates all the startup noise by tomcat, and all other logging will be performed by the logging framework of your choice anyways (logback in my case), so this should not affect your standard logging at all.
Solution 2:[2]
The Apache juli logs can be omitted by setting java.util.logging formatter system property to empty String before SpringBootApplication start like this
System.setProperty("java.util.logging.SimpleFormatter.format", "");
Solution 3:[3]
You can set the following in the application.properties:
logging.group.tomcat=org.apache.catalina, org.apache.coyote, org.apache.tomcat
logging.level.tomcat=OFF
Since the embedded Tomcat uses the JUL, this will set the JUL logging level regarding the Tomcat related classes to OFF.
Solution 4:[4]
Look at the Loggername (in case of Log4j(2)) appearing in the console.
Then, copy the name and prepend it to logging.level. in you application.properties file.
In the screenshot below, if I uncomment the line of DispatcherServlet the logging goes away:
Solution 5:[5]
A slightly less obtrusive method is to specify a JUL configuration properties file as system property (cf. JUL JavaDoc and How to set up java logging using a properties file? (java.util.logging)) and merely reduce the log level as required in that.
So add such a system property: -Djava.util.logging.config.file=logging.properties
And use a configuration like this in that file:
.level=WARNING
handlers=java.util.logging.ConsoleHandler
java.util.logging.ConsoleHandler.level=WARNING
Using WARNING will silence all Tomcat startup logging but still show any problems.
Yet another approach would be to re-route JUL logs to log4J or Logback, cf.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Alan47 |
| Solution 2 | Jeffry Jacob D |
| Solution 3 | |
| Solution 4 | Kejsi Struga |
| Solution 5 |

