log4j and MSSQL

641 views
Skip to first unread message

Marcelo Olivas

unread,
Apr 14, 2011, 12:21:07 PM4/14/11
to mybati...@googlegroups.com
Hi guys!  I'm working on a new project with MSSQL.  My software stack is very ordinary: Spring 3.0, myBatis 3.0.5, mybastis-spring 1.0.1, and the latest MSSQL server using the slqjdbc4.jar.  

For some reason, I don't see to get any logging from java.sql or iBatis.  Here's what I've done so far:
- Added the log4j library
- Added the log4.properties in the src directory
- Make sure that the log4.properties is in the bin directory
- Noticed that I am getting logging from Spring
- Configured the log4j.properties with the following syntax:

### Global logging configuration
log4j.rootLogger=DEBUG, stdout

### Uncomment ALL for iBATIS logging
log4j.logger.org.apache=DEBUG
log4j.logger.org.apache.ibatis=DEBUG
log4j.logger.org.apache.ibatis.common.jdbc.SimpleDataSource=DEBUG
log4j.logger.org.apache.ibatis.common.jdbc.ScriptRunner=DEBUG
log4j.logger.org.apache.ibatis.sqlmap.engine.impl.SqlMapClientDelegate=DEBUG
log4j.logger.org.apache.ibatis.cache.decorators.LoggingCache=DEBUG
log4j.logger.java.sql.Connection=DEBUG
log4j.logger.java.sql.Statement=DEBUG
log4j.logger.java.sql.PreparedStatement=DEBUG
log4j.logger.java.sql.ResultSet=DEBUG


log4j.logger.org.springframework.jdbc=DEBUG 

log4j.logger.org.springframework=DEBUG
org.mybatis.spring=DEBUG

log4j.logger.org.springframework=DEBUG
### Console output...
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%5p [%t] - %m%n


Thanks for all your help!
Marcelo

nino martinez wael

unread,
Apr 14, 2011, 2:23:44 PM4/14/11
to mybati...@googlegroups.com
mine looks like this, although in xml format and works although I am
including something twice somewhere probably the sql :

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">

<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
<appender name="console" class="org.apache.log4j.ConsoleAppender">
<param name="Target" value="System.out"/>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d %-5p [%C] %x - %m%n"/>
</layout>
</appender>

<appender name="stdout" class="org.apache.log4j.ConsoleAppender">
<layout class="org.apache.log4j.PatternLayout">
<!-- Pattern to output the caller's file name and line number -->
<param name="ConversionPattern" value="%5p [%t] (%F:%L) - %m%n"/>
</layout>
</appender>
<appender name="RollingFile" class="org.apache.log4j.RollingFileAppender">
<param name="file" value="${catalina.home}/logs/NetDesignCCAdmin.log"/>
<param name="MaxFileSize" value="5192KB"/>
<!-- Keep 10 backup files -->
<param name="MaxBackupIndex" value="10"/>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d %5p [%t] (%F:%L) - %m%n"/>
</layout>
</appender>

<logger name="com.netdesign">
<level value="debug"/>
<appender-ref ref="console" />
</logger>
<logger name="javax.sql">
<level value="debug"/>
<appender-ref ref="console" />
</logger>
<logger name="java.sql">
<level value="debug"/>
<appender-ref ref="console" />
</logger>

<root>
<priority value="info" />
<appender-ref ref="console" />
<appender-ref ref="RollingFile" />
</root>
</log4j:configuration>


2011/4/14 Marcelo Olivas <mfol...@gmail.com>:

Marcelo Olivas

unread,
Apr 14, 2011, 5:12:57 PM4/14/11
to mybati...@googlegroups.com
Thanks Nino! I just tried it and unfortunately, it did not work.  I'm not sure if its due to MSSQL.  I did not see any of the prepared statement in the output file or the console.

Guy Rouillier

unread,
Apr 14, 2011, 10:37:09 PM4/14/11
to mybati...@googlegroups.com
Verify that log4j.properties is on your runtime classpath. Just putting
it in your source directory doesn't guarantee that. But I don't use
Spring, so perhaps Spring does something special in that regard.


On 4/14/2011 12:21 PM, Marcelo Olivas wrote:
> Hi guys! I'm working on a new project with MSSQL. My software stack is
> very ordinary: Spring 3.0, myBatis 3.0.5, mybastis-spring 1.0.1, and the
> latest MSSQL server using the slqjdbc4.jar.
>
> For some reason, I don't see to get any logging from java.sql or iBatis.
> Here's what I've done so far:
> - Added the log4j library
> - Added the log4.properties in the src directory
> - Make sure that the log4.properties is in the bin directory
> - Noticed that I am getting logging from Spring
> - Configured the log4j.properties with the following syntax:
>
> ### Global logging configuration
> log4j.rootLogger=DEBUG, stdout
>
> ### Uncomment ALL for iBATIS logging
> log4j.logger.org.apache=DEBUG
> log4j.logger.org.apache.ibatis=DEBUG
> log4j.logger.org.apache.ibatis.common.jdbc.SimpleDataSource=DEBUG
> log4j.logger.org.apache.ibatis.common.jdbc.ScriptRunner=DEBUG
> log4j.logger.org.apache.ibatis.sqlmap.engine.impl.SqlMapClientDelegate=DEBUG
> log4j.logger.org.apache.ibatis.cache.decorators.LoggingCache=DEBUG
> log4j.logger.java.sql.Connection=DEBUG
> log4j.logger.java.sql.Statement=DEBUG
> log4j.logger.java.sql.PreparedStatement=DEBUG

> log4j.loggerjava.sql.ResultSet=DEBUG


>
>
> log4j.logger.org.springframework.jdbc=DEBUG
>
> log4j.logger.org.springframework=DEBUG
> org.mybatis.spring=DEBUG
>
> log4j.logger.org.springframework=DEBUG
> ### Console output...
> log4j.appender.stdout=org.apache.log4j.ConsoleAppender
> log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
> log4j.appender.stdout.layout.ConversionPattern=%5p [%t] - %m%n
>
>
> Thanks for all your help!
> Marcelo


--
Guy Rouillier

Larry Meadors

unread,
Apr 14, 2011, 11:25:01 PM4/14/11
to mybati...@googlegroups.com
Also - check to see that it's the ONLY log4j.properties on your classpath.

Some tools (like apache axis) give you a log4j.properties file that
supplants yours. Sucks.

Larry

meindert hoving

unread,
Apr 15, 2011, 3:15:25 AM4/15/11
to mybatis-user
I've got the same issue, all logging beside mybatis logging works.
The only way I could get it to work is by placing commons-
logging-1.1.jar on the class path.
It would be nice to know If anybody has a better solution, because it
seems that commons-logging doesn't release resources when you reload
the application ?

Cheers
Meindert
On Apr 14, 6:21 pm, Marcelo Olivas <mfoli...@gmail.com> wrote:
> Hi guys!  I'm working on a new project with MSSQL.  My software stack is
> very ordinary: Spring 3.0, myBatis 3.0.5, mybastis-spring 1.0.1, and the
> latest MSSQL server using the slqjdbc4.jar.
>
> For some reason, I don't see to get any logging from java.sql or iBatis.
>  Here's what I've done so far:
> - Added the log4j library
> - Added the log4.properties in the src directory
> - Make sure that the log4.properties is in the bin directory
> - Noticed that I am getting logging from Spring
> - Configured the log4j.properties with the following syntax:
>
> ### Global logging configuration
> log4j.rootLogger=DEBUG, stdout
>
> ### Uncomment ALL for iBATIS logging
> log4j.logger.org.apache=DEBUG
> log4j.logger.org.apache.ibatis=DEBUG
> log4j.logger.org.apache.ibatis.common.jdbc.SimpleDataSource=DEBUG
> log4j.logger.org.apache.ibatis.common.jdbc.ScriptRunner=DEBUG
> log4j.logger.org.apache.ibatis.sqlmap.engine.impl.SqlMapClientDelegate=DEBU­G

Marcelo Olivas

unread,
Apr 15, 2011, 12:42:03 PM4/15/11
to mybati...@googlegroups.com
Indeed, I placed the following log4j.xml in the src and make sure that it was also in my classpath (bin) directory when it compiled.  I don't see any of the java.sql.* .  However, I see one line that comes out:
DEBUG 04-15 12:39:14 No property editor [org.apache.ibatis.session.ExecutorTypeEditor] found for type org.apache.ibatis.session.ExecutorType according to 'Editor' suffix convention  (BeanUtils.java:421) 

So, I guess that it the logging is working for the org.apache.ibatis, but what I really need is to check all my sql statements.

Here is my log4j.xml

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">

<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
    
    <!-- Console output -->

    <appender name="STDOUT" class="org.apache.log4j.ConsoleAppender">
        <layout class="org.apache.log4j.PatternLayout">
            <param name="ConversionPattern" value="%-5p %d{MM-dd HH:mm:ss} %m  (%F:%L) \n"/>
        </layout>
    </appender>
    <category name="org.apache.commons">
     <priority value="debug" />
    </category>
    <category name="org.springframework">
     <priority value="debug" />
    </category>
    <category name="org.mybatis">
        <priority value="debug" />
    </category>
    <category name="java.sql">
        <priority value="debug" />
    </category>
    <category name="java.sql.ResultSet">
        <priority value="debug" />
    </category>
    <category name="java.sql.Connection">
        <priority value="debug" />
    </category>
    <category name="java.sql.Statement">
        <priority value="debug" />
    </category>
    <category name="java.sql.PreparedStatement">
        <priority value="debug" />
    </category>
    <category name="org.apache.ibatis">
        <priority value="debug" />
    </category>
    <root>
        <priority value ="debug" />
        <appender-ref ref="STDOUT" />
    </root>
    
</log4j:configuration>

nino martinez wael

unread,
Apr 16, 2011, 3:12:27 AM4/16/11
to mybati...@googlegroups.com
I have it working here, please tell me if you need information... Im
using a maven based project and can supply the pom if needed?

2011/4/15 meindert hoving <meinder...@gmail.com>:

mfol...@gmail.com

unread,
Apr 16, 2011, 3:03:07 PM4/16/11
to mybati...@googlegroups.com
Hey Nino! Can you please tell me what's the driver you're using and the log4j.xml/properties. I am not using maven for this project.

Thanks,
Marcelo
Twitter/Skype: mfolivas
Sent from my Verizon Wireless BlackBerry

nino martinez wael

unread,
Apr 18, 2011, 2:11:03 AM4/18/11
to mybati...@googlegroups.com
Microsoft driver :

<dependency>
<groupId>com.microsoft</groupId>
<artifactId>sqljdbc4</artifactId>
<version>3.0CTP</version>
</dependency>
Log4J xml:


<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">

<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">

<appender name="console" class="org.apache.log4j.ConsoleAppender">
<param name="Target" value="System.out"/>

<layout class="org.apache.log4j.PatternLayout">


<param name="ConversionPattern" value="%d %-5p [%C] %x - %m%n"/>
</layout>
</appender>

<appender name="stdout" class="org.apache.log4j.ConsoleAppender">
<layout class="org.apache.log4j.PatternLayout">


<!-- Pattern to output the caller's file name and line number -->
<param name="ConversionPattern" value="%5p [%t] (%F:%L) - %m%n"/>
</layout>
</appender>
<appender name="RollingFile" class="org.apache.log4j.RollingFileAppender">
<param name="file" value="${catalina.home}/logs/NetDesignCCAdmin.log"/>
<param name="MaxFileSize" value="5192KB"/>
<!-- Keep 10 backup files -->
<param name="MaxBackupIndex" value="10"/>

<layout class="org.apache.log4j.PatternLayout">


<param name="ConversionPattern" value="%d %5p [%t] (%F:%L) - %m%n"/>
</layout>
</appender>

<logger name="com.netdesign">
<level value="debug"/>
<appender-ref ref="console" />
</logger>
<logger name="javax.sql">
<level value="debug"/>
<appender-ref ref="console" />
</logger>
<logger name="java.sql">
<level value="debug"/>
<appender-ref ref="console" />
</logger>

<root>
<priority value="info" />
<appender-ref ref="console" />
<appender-ref ref="RollingFile" />
</root>
</log4j:configuration>


2011/4/16 <mfol...@gmail.com>:

Marcelo Olivas

unread,
Apr 19, 2011, 12:53:39 PM4/19/11
to mybati...@googlegroups.com
Nino, so sorry, it is not working. I'm not sure if its have to do with the ibatis-spring version that I have or the version of my driver. I'm going to make sure that I use the same version that you have for sqljdbc4.  Are you using spring-ibatis? I'm using the latest release version.

Thanks,
Marcelo

twitter/skype: mfolivas

Jeff Butler

unread,
Apr 19, 2011, 4:13:20 PM4/19/11
to mybati...@googlegroups.com
Please read out the logging section in the user's guide. It is likely
that you have some other logging system (like SLF or JCL) in your
classpath. If that is the case, the MyBatis might never see your
log4j properties file because it will select one of the other logging
implementations first. If you want to force MyBatis to use log4j,
then execute this line of code:

org.apache.ibatis.logging.LogFactory.useLog4JLogging();

Make sure to do this before calling any other MyBatis code.

Jeff Butler

nino martinez wael

unread,
May 2, 2011, 1:47:30 PM5/2/11
to mybati...@googlegroups.com
Sorry Marcelo for the late answer...

No Im using the Guice version..

2011/4/19 Marcelo Olivas <mfol...@gmail.com>:

Marcelo Olivas

unread,
May 24, 2011, 2:05:39 PM5/24/11
to mybati...@googlegroups.com
Hi guys, I finally found the error thanks to Jeff!  Once I forced myBatis to use the log4j via:
org.apache.ibatis.logging.LogFactory.useLog4JLogging();

I started seeing the logging.

Unfortunately, these APIs are used by the Spring 3.0 framework. The only problem is that in my unit-test cases, I don't see the logging.  I'm looking at all the APIs that I have, but my guess is that it is commons-logging.  I was wondering if any of you guys have this issue or if perhaps I'm using the wrong api for commons-logging.  I'm using commons-logging-1.1.1.jar

Thanks,
Marcelo
Reply all
Reply to author
Forward
0 new messages