SQL server does not support logging queries, but this feature is available in MySQL and PostGREs
5. Modify the database_params file or any other database config file and make changes to the jdbc url and driver class name as follows. (sample attached)
6. Restart the application for the changes to take effect. all the queries which pass through the jdbc driver will get printed in the sql.log as mentioned in the log4j.properties
We have to follow the steps below to enable logging in SQL Server based tomcat/java application.
1. Download the necessary jar files. (choose whichever version is latest)
1. log4jdbc4-1.2.jar
2. log4j-over-slf4j-1.7.7.jar
3. log4j-1.2.16.jar
2. Place them in the lib folder and make sure they are added in class path.
3. Place log4j.properties in the lib folder as well and include it in class path.
4. configure the location where the log file must be written with respect to the deployed folder.
log4j.appender.Log4JDBC.File=../logs/sql.log
5. Modify the database_params file or any other database config file and make changes to the jdbc url and driver class name as follows. (sample attached)
drivername=net.sf.log4jdbc.DriverSpy
url=jdbc:log4jdbc:jtds:sqlserver://hostname:1433;databasename=dbname;useLOBs=false;
6. Restart the application for the changes to take effect. all the queries which pass through the jdbc driver will get printed in the sql.log as mentioned in the log4j.properties
Comments
Post a Comment