Comments (3)
What do you see with -Dlog4j2.debug=true set? Can you please provide those logs
from logging-log4j2.
In attach the logs retrieved after Dlog4j2.debug=true setting.
catalina.log
from logging-log4j2.
Your problem is caused by multiple log4j-api
and log4j-core
jars being loaded into your Tomcat system (your logs show 3 instances of ClassLoaderContextSelector
, one for each web application). Each one opens a file descriptor to your log file and each one tries to rotate it. As you can imagine, this does not end well.
Log4j2 is perfectly capable of sharing the same log file between logging context, if a single copy of log4j-core
is deployed in your system. Technically each logging context will then have its own copy of RollingFileAppender
, but the engine that opens files and performs the rotation (RollingFileManager
) will be shared.
Unlike full application servers such as Wildfly, Tomcat has not easy way to share a single library between web applications. In order to do that you need to install a set of Log4j2 artifacts in the $CATALINA_BASE/lib
folder and do one of the following:
- Remove the
log4j-*
artifacts from your web applications (personally I don't like the idea of modifying web applications), - Switch the delegation model of all web application classloaders to "parent first" (this might break some apps if they need different versions of the same library), by adding:
to their context configuration (e.g. in
<Loader delegate="true"/>
$CATALINA_BASE/conf/context.xml
). Cf. Tomcat documentation. - Use a custom classloader that looks up
org.apache.logging.log4j.*
classes in the parent classloader first, but uses the usual delegation for the other classes. This is basically what Tomcat does withorg.apache.catalina.*
and other internal classes.
You can find such a classloader in my personal repository (cf. Log4jWebappClassloader
). You can find it on Maven Central under the coordinates:
<dependency>
<groupId>eu.copernik</groupId>
<artifactId>log4j-tomcat</artifactId>
<version>2.18.0</version>
</dependency>
To use it, place it in the $CATALINA_BASE/lib
folder together with log4j-api
and log4j-core
and add:
<Loader loaderClass="eu.copernik.log4j.tomcat.Log4jWebappClassLoader"/>
to your $CATALINA_BASE/conf/context.xml
file.
from logging-log4j2.
Related Issues (20)
- Revamp the `Configuration` page HOT 2
- Revamp the `Lookups` page
- Revamp the `Layouts` page
- Revamp the `Appenders` page HOT 1
- Revamp the `Filters` page
- Revamp the `Extending` page
- Revamp the `Plugins` page
- Create a `Troubleshooting` page
- Revamp the `Performance` page
- Revamp the `Asynchronous logging` page
- Revamp the `API` page
- Uniform handling of location and URIs HOT 1
- [MS14] Documentation revamp 1/5
- [MS15] Documentation revamp 2/5
- [MS16] Documentation revamp 3/5
- [MS17] Documentation revamp 4/5
- [MS18] Documentation revamp 5/5
- Revamp the `Web Applications` page
- Implement uniform password "encryption/decryption" mechanism HOT 2
- When logging from multiple threads, an appender can be broken until app restart if it rolls over HOT 10
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from logging-log4j2.