4

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.

Martin Häusler
  • 6,544
  • 8
  • 39
  • 66

5 Answers5

2

Okay, it took me about 5 hours to figure this out:

  • Tomcat uses JULI, a derivative of java.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.

Martin Häusler
  • 6,544
  • 8
  • 39
  • 66
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", "");

1

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.

Sofo Gial
  • 697
  • 1
  • 9
  • 20
  • I believe it should be set to `OFF` to disable all messages? `TRACE` will show everything, small mistake, I think. – Mark Jan 08 '19 at 14:28
  • As far as I know, embedded Tomcat uses JULI, a fork of JUL of some sorts. I just tried your solution, unfortunately it didn' work - the logs still appear on my console... – Martin Häusler Jan 08 '19 at 14:41
0

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:

enter image description here

Kejsi Struga
  • 550
  • 6
  • 21
0

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.

Hein Blöd
  • 1,553
  • 1
  • 18
  • 25