Git Product home page Git Product logo

Comments (3)

rgoers avatar rgoers commented on May 18, 2024

What do you see with -Dlog4j2.debug=true set? Can you please provide those logs

from logging-log4j2.

mariusv5 avatar mariusv5 commented on May 18, 2024

In attach the logs retrieved after Dlog4j2.debug=true setting.
catalina.log

from logging-log4j2.

ppkarwasz avatar ppkarwasz commented on May 18, 2024

@mariusv5,

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:

  1. Remove the log4j-* artifacts from your web applications (personally I don't like the idea of modifying web applications),
  2. 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:
    <Loader delegate="true"/>
    
    to their context configuration (e.g. in $CATALINA_BASE/conf/context.xml). Cf. Tomcat documentation.
  3. 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 with org.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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.