How can log4j be configured for MyBatis in a JUnit run configuration on Eclipse?
There are several such questions on SO and the internet. But, most of the suggestions don't seem to work for me.
Specifically, the following doesn't seem to work: (from the MyBatis logging page)
1. log4j-1.2.16.jar is on my Eclipse's Java Build Path Libraries (under Maven Dependencies).
2. log4j.properties is on my Run Configuration. It's under VM arguments as: -Dlog4j.configuration=C:\log4j.properties
3. My log4j.properties file contains the below code.
log4j.appender.stdout.layout.ConversionPattern=%5p [%t] - %m%n
As per my understanding, things will work if I can keep the log4j.properties file on the Eclipse classpath. But, I'm not sure if the run configuration VM arguments sets the classpath.
If I force MyBatis to use log4j,
The following is output on the console:
log4j:WARN No appenders could be found for logger (org.apache.ibatis.logging.LogFactory).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
On 1/31/2013 1:30 PM, maelstrom3 wrote:
> How can *log4j *be configured for *MyBatis *in a *JUnit *run
> configuration on *Eclipse*?
I've done it fairly easily.
> 2. log4j.properties is on my Run Configuration. It's under VM arguments
> as: -Dlog4j.configuration=C:\log4j.properties
I don't use this.
> 3. My log4j.properties file contains the below code.
> log4j.rootLogger=ERROR, stdout
> log4j.appender.stdout.layout.ConversionPattern=%5p [%t] - %m%n
You need more than that:
> As per my understanding, things will work if I can keep the
> log4j.properties file on the Eclipse classpath. But, I'm *not sure if
> the run configuration VM arguments sets the classpath*.
I believe this is the core issue. When you try to run or debug, look at
Run Configurations... . Make sure your configuration is under JUnit,
and that Test runner is set to JUnit 4. I don't have anything in
Arguments, Classpath, Source or Environment other than what is added
automatically from the project.
However, I did have to add the folder containing log4j.properties as a
Source folder to the project. That's because I'm working with a web
project, and all the sources end up in WEB-INF/classes after being
built, and that directory is constitutes the classpath for a web app.
You don't say what type of app you are building, but make sure that
log4j.properties ends up on the classpath for JUnit, and you should be
> If I force MyBatis to use log4j,
> The following is output on the console:
> log4j:WARN No appenders could be found for logger
> log4j:WARN Please initialize the log4j system properly.
That's pretty convincing evidence that your JUnit runtime environment is
not finding log4j.properties.
You received this message because you are subscribed to the Google Groups "mybatis-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/groups/opt_out.
This worked well. It was the missing piece.
After putting the file in the source folder, my eclipse was probably not copying the log4j.properties file into the target/test-classes folder. So, I had to clean and rebuild the project.
Thanks Guy Rouillier-2, for the tip.
|Powered by Nabble||Edit this page|