Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3634418
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T00:46:35+00:00 2026-05-19T00:46:35+00:00

I have a common jar that multiple web applications are using. All the web

  • 0

I have a common jar that multiple web applications are using. All the web applications are using log4j. Each has their own log4j xml configuration file that are basically the same. I would like to put a common log4j configuration in the included jar file and in each individual web project, in that log4j configuration, I would like to be able to simply refer to the one in the jar file.

I’m not seeing anything in the documentation that explicitly says this is possible. I’m wondering if I might just remove the configuration file from the web projects and stick it in the common jar if it would get loaded automatically since it is on the class path?

In the end, I would like the ability to adjust logging on a particular application for debugging and troubleshooting without modifying the common configuration in the jar file.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T00:46:35+00:00Added an answer on May 19, 2026 at 12:46 am

    I was on a project where I needed to manage dozens of web applications. Each of the apps were logging slightly differently and it was a pretty big pain to manage. I used a strategy similar to what you are describing to standardize on log4j and it has worked out pretty well.

    Basically, I created a single common.jar which contains shared code. This jar contains a log4j.xml that sets log level to INFO and sets the default appender to stdout for common.jar. This log4j config is used as the baseline for all other apps.

    For this example, pretend this class is inside common.jar:

    public class ThirdPartyLib 
    {
        protected static final Logger log = LogManager.getLogger("third-party-lib");
        public void doSomething()
        {
            log.debug("Third Party App is about to Do something!");
            log.info("Third Party App just did something");
        }
    }
    

    Now, all other web applications can simply depend on common.jar. For example, pretend this class is inside myapp.war:

    public class MyApp
    {
        public void CallThirdParty()
        {
            ThirdPartyLib lib = new ThirdPartyLib();
            lib.doSomething();
        }
    }
    

    Since log4j.xml is inside common.jar, this code will log something like this. In other words, there’s no need to put log4j.xml inside myapp.war:

    2011-01-03 15:49:22,451 [main] INFO  third-party-lib - Third Party App just did something
    

    Now, if you want/need to control logging in myapp.war, then simply place a log4j.xml inside myapp.war and override settings from common.jar. For example, you might set the level to DEBUG, and then you’ll see:

    2011-01-03 16:03:22,928 [main] DEBUG third-party-lib - Third Party App is about to Do something!
    2011-01-03 16:03:22,928 [main] INFO  third-party-lib - Third Party App just did something
    

    UPDATE – Is it possible to configure each webapp to log to separate file?

    Yes, definitely. For example, you can direct logs to a RollingFileAppender instead of stdout inside log4j.xml for myapp.war. This is handy because then you can have each individual webapp log to it’s own separate file.

    In addition, I wrote a servlet filter (similar to what gigadot suggested) which configures log4j to check for whether a log4j.xml exists at an external path (outside of each webapp’s war). This way, the log4j.xml files are accessible outside the wars and we’re able to set log levels without restarting the servlet container (tomcat, in this case). If the external log4j.xml doesn’t exist, it defaults to use the log4j.xml on each apps classpath.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a project where there are multiple applications that have some common configuration
We have several common libs. Ideally we want them all to use the latest
i have several common elements (components), that will generate some html. it seems my
I want to create templates for base new reports on to have common designs.
We have a common problem of moving our development SQL 2005 database onto shared
I have a common code of serializing a class object in my 3-4 methods
Do you have a common base class for Hibernate entities, i.e. a MappedSuperclass with
I would love to be able to have a common set of Classes in
It's common to have a table where for example the the fields are account,
I have a very common situation. I have a file, and I need to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.