Domanda

To elaborate on that, I have a Tomcat server version 7.0.27 running Java 1.6.0_27.

I have two wars, each with their own log4j jar, also using slf4j with slf4j-log4j. Each war has it's own configuration file (log4j.xml).

war 1 should use file log-1.log and war 2 should use file log-2.log but both are logging into log-1.log.

I've checked there are no other log4j jars in the tomcat installation so I'm not sure where the problem is. I've also turned off shared class loading but that made no difference. My next step is to turn on verbose class loader logging and/or start debugging log4j but maybe someone here knows why this is and can save me some time. Thanks for any input on this.

Update:

Ok think I got this one. The log4j xml files are fine. After doing a verbose:class I can see that log4j.jar is only getting loaded once and from neither web application.

I'm working with Documentum. They have a runtime jar required to use their libraries that is an empty jar with a manifest file. The manifest points to a bunch of jars. In other words, they don't use maven... Anyway ... one of those jars happens to be logj4 found in the Documentum installation. So it seems both webapps are using that one. I think this is the problem. To be confirmed...

È stato utile?

Soluzione

If you are placing Documentum's runtime jar on your top-level classpath, and that runtime jar is referencing log4j.jar, then it will only load once. You don't have to use that runtime jar, though, or you can use it in just your Documentum .war, if one is non-Documentum.

Altri suggerimenti

You didn't post your properties file but i can think of some reasons:

  1. You don't have an appender that writes to the different files, i.e you need appender1 to write to log1.log and appender2 writing to log2.txt
  2. You have the appenders set up right but both the applications are using the same logger, so they both write to the same file.
  3. You have 2 loggers, each with its own appender, but in your code you are not initializing the correct logger:

    //there is no logger called com.sample, so it defaults to root logger that has appender that writes to log1.txt    
    Logger logger = Logger.getLogger(com.sample.MyClass.class);
    

If you post your properties file and your logger init code it'll be easier to help you.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top