javaspringloggingmybatisspring-mybatis

Im Trying to log queries , doesnt matter if they're unprepared ones , for over 500 xml mapper files using jdk logger . (mybatis - spring )


previously when I used to used ibatis , it was running fine just by adding java.sql to my logs.properties file in tomcat and that used to output the queries with their params to the log file .

now since I switched from ibatis to mybatis and also from spring 1.2 to spring 5 (i can't really tell where the problem came from at this point ) I'm not able to log queries as I used before. specifying java.sql in my logs.properties doesn't print out any logs to my file.

all my configurations are XML based.

The only way I'm able to log queries so far is through including the namespace of the XML mapper to my logs.properties file but this is just unrealistic for over 500 XML files that are in different locations at some point.

I'm trying to find a class that I can include in my logs.properties file that would be able to do the same job as java.sql


Solution

  • If there is a 'package' common to your mappers' namespaces, you can set the log level against the package.
    Let's say you have two mappers whose namespaces are foo.mapper.MapperA and foo.mapper.MapperB respectively.
    The common package, in this case, is foo.mapper.

    When there is no common package, you may have to set log level for each mapper if you want to log all statements.
    This is not an ideal solution when you have 500 mappers, obviously.
    In such a scenario, I would suggest using an external JDBC logging tool like JdbcDsLog.