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)
log4j-1.2.16.jaris on my Eclipse’sJava Build Path Libraries(under Maven Dependencies).- log4j.properties is on my
Run Configuration. It’s under VM arguments as:-Dlog4j.configuration=C:\log4j.properties - My log4j.properties file contains the below code.
log4j.rootLogger=ERROR, stdout
log4j.logger.org.mybatis.example.BlogMapper=TRACE
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
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.
EDIT
If I force MyBatis to use log4j,
org.apache.ibatis.logging.LogFactory.useLog4JLogging();
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.
Got the answer:
http://mybatis-user.963551.n3.nabble.com/log4j-for-MyBatis-in-a-JUnit-run-configuration-on-Eclipse-tp4026384p4026393.html
An alternate way to set the classpath is as described in the answer by @sivaprasadreddy.k