I'm using embedded Tomcat 8.5.4, i.e.,
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-core</artifactId>
<version>8.5.4</version>
</dependency>
The implementation is working perfectly (Tomcat works like a charm), the only thing that's bothering me, is that the embedded Tomcat logs on System.out
. Internally within my application I'm using log4j
for logging, so this leads to the following logging mixture (and not logging of Tomcat to any file):
...
2017-07-30 17:57:54 DEBUG EmbeddedTomcat:136 - Binding servlet 'sample' to path '/sample/*'.
Jul 30, 2017 5:57:54 PM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["http-nio-15000"]
Jul 30, 2017 5:57:54 PM org.apache.tomcat.util.net.NioSelectorPool getSharedSelector
INFO: Using a shared selector for servlet write/read
Jul 30, 2017 5:57:54 PM org.apache.catalina.core.StandardService startInternal
INFO: Starting service Tomcat
Jul 30, 2017 5:57:54 PM org.apache.catalina.core.StandardEngine startInternal
INFO: Starting Servlet Engine: Apache Tomcat/8.5.4
Jul 30, 2017 5:57:54 PM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler [http-nio-15000]
2017-07-30 17:57:54 INFO EmbeddedTomcat:80 - Successfully started Tomcat on port 15000 (base: null, url: http://localhost:15000).
...
In this snippet the first and the last line (after and before the ...
) are logged by my application using log4j and the configuration of log4j (which writes to a file and the System.out
). Nevertheless, the middle part (logging of Tomcat) is handled by the Embedded Tomcat and I have no clue, how to get Tomcat to use the available log4j (and it's configuration).
I tried to add the following dependency (a 8.5.4
version is not available on Maven Repository or Maven Central), but without any success.
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-logging-log4j</artifactId>
<version>8.5.2</version>
</dependency>
Does anyone know how to get the Embedded Tomcat to log using log4j (Version 1, I'm not using log4j2)?
I looked at/tried the following StackOverflow answers:
https://tomcat.apache.org/tomcat-8.0-doc/logging.html So I looked at the documentation, which mentions
log4j
as logging framework. It mentionstomcat-juli-adapters.jar
, which I could not find for the embedded version (is it the same as the "normal" Tomcat?). How would I do that programmatically, i.e., within my Embedded Tomcat implementation.Tomcat Logging using log4j? That's not really the problem I'm having, it's not based on the Embedded Tomcat, the version is pretty old, and I'm actually using log4j not
System.out
.Embedded Tomcat logging over logback / sl4j This question actually deals with
logback
and the author mentions thatI found some info about using a standalone tomcat with log4j
, but the standalone is different, I see the author is using similar dependencies, but not sure if there was ever a solution.How to enable embedded tomcat logging First I thought his may be the solution, but it all just deals with an additional logging for the Embedded Tomcat. I want the Embedded Tomcat to use the applications
log4j
, so onelog4j.properties
file, which defines how everything is logged.Logging in Embedded Tomcat I'm not sure why this answer is even marked as correct, but this is just an explanation how Tomcat writes the
catalina.out
file and not how the logging of the Embedded Tomcat works.