iBATIS 2.3.3.720
Log4j 1.2.14
iBATISでSQL(select文)を実行すると、DEBUGレベルでこのような形でログが出力される。
yyyy-MM-dd HH:mm:ss.SSS,DEBUG,java.sql.Connection,{conn-xxxxxx} Connection yyyy-MM-dd HH:mm:ss.SSS,DEBUG,java.sql.Connection,{conn-xxxxxx} Preparing Statement: … yyyy-MM-dd HH:mm:ss.SSS,DEBUG,java.sql.PreparedStatement,{pstm-xxxxxx} Executing Statement: … yyyy-MM-dd HH:mm:ss.SSS,DEBUG,java.sql.PreparedStatement,{pstm-xxxxxx} Parameters: … yyyy-MM-dd HH:mm:ss.SSS,DEBUG,java.sql.PreparedStatement,{pstm-xxxxxx} Types: … yyyy-MM-dd HH:mm:ss.SSS,DEBUG,java.sql.ResultSet,{rset-xxxxxx} ResultSet yyyy-MM-dd HH:mm:ss.SSS,DEBUG,java.sql.ResultSet,{rset-xxxxxx} Header: … yyyy-MM-dd HH:mm:ss.SSS,DEBUG,java.sql.ResultSet,{rset-xxxxxx} Result: … … (検索結果の行数分出力される) … yyyy-MM-dd HH:mm:ss.SSS,DEBUG,java.sql.ResultSet,{rset-xxxxxx} Result: …
java.sql.ResultSetの結果が、検索結果の行数分出力され、ログが多すぎてログファイルが大きくなるため、発行したSQLのログだけ取得したい。
そのため、下記のようにlog4j.propertiesの設定を行って、java.sql.PreparedStatementのログのみDEBUGレベルで出力するように設定したが、ログが全く出力されなくなった。
log4j.logger.java.sql = INFO, sqllog log4j.logger.java.sql.ResultSet = INFO log4j.logger.java.sql.Connection = INFO log4j.logger.java.sql.PreparedStatement = DEBUG
@IT会議室 > iBATISで発行したSQLのログの出し方
の記事にあるように、java.sql.Connectionも同じくDEBUGレベルで出力するように設定することで、発行したSQLのログが出力できる(SQLの結果がログに出力されないようになる)。
log4j.logger.java.sql = INFO, sqllog log4j.logger.java.sql.ResultSet = INFO log4j.logger.java.sql.Connection = DEBUG log4j.logger.java.sql.PreparedStatement = DEBUG
yyyy-MM-dd HH:mm:ss.SSS,DEBUG,java.sql.Connection,{conn-xxxxxx} Connection yyyy-MM-dd HH:mm:ss.SSS,DEBUG,java.sql.Connection,{conn-xxxxxx} Preparing Statement: … yyyy-MM-dd HH:mm:ss.SSS,DEBUG,java.sql.PreparedStatement,{pstm-xxxxxx} Executing Statement: … yyyy-MM-dd HH:mm:ss.SSS,DEBUG,java.sql.PreparedStatement,{pstm-xxxxxx} Parameters: … yyyy-MM-dd HH:mm:ss.SSS,DEBUG,java.sql.PreparedStatement,{pstm-xxxxxx} Types: …