1
votes

I successfully configured log4j configuration by placing log4j.properties file inside in src/main/webapp/WEB-INF/classes folder. The logs for the application was working fine but my JUnit test cases logging was not working.

Searched over the internet and found out that I have to place my log4j.properties file inside src/test/resources for my JUnit test cases logging. Did so and logging for JUnit test cases also started working.

Deployed my application in my server after that and the log4j is now reading log4j.properties file from src/test/resources instead of one from WEB-INF/classes directory (the JUnit log4j.properties file creates a different log file for logging, and the logs are being written in that log file).

The application (maven project and not the war file) is being deployed in my weblogic server inside eclipse.

Please let me know how can i resolve this log4j configuration issue, so that my server uses the correct log4j configuration file.

log4j import:

import org.apache.log4j.Logger;

Logger instantiation:

private static Logger logger = Logger.getLogger(TestClass.class);
1
if maven is normaly configured its all fine. Maven normaly take care about your build and deploys the build correctly wherever you want. You put it in the right direction as it seems. so where is the problem?Rubinum
@Rubinum: What maven has to do with this? I am not using maven for deployment.Ankit
ah you dont use maven. than i am sorry ^^.Rubinum
Maven is a build-management-software, maven only is allowed to create the war-file you deploy using maven war:war!Grim

1 Answers

2
votes

This is probably your IDE environments' issue. I think your IDE has test packages marked as source directories and when your IDE deploys web app, weblogic has your test packages on classpath.

Log4j seeks for configuration on classpath, so it likely sees test/log4j.properties first.

My 2 suggestions:

  1. try to mark test/src as not exported to weblogic (or exluded from deploy - this is IDE specific)
  2. force log4j configuration file by setting -Dlog4j.configuration=path/to/log4j.properties inside your weblogic startup configuration