Last active
October 17, 2016 19:50
-
-
Save iromu/4351349 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8"?> | |
<aspectj> | |
<aspects> | |
<aspect name="com.package.StatementTracing" /> | |
</aspects> | |
</aspectj> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import org.aspectj.lang.annotation.Aspect; | |
import org.aspectj.lang.annotation.Before; | |
import org.aspectj.lang.annotation.Pointcut; | |
import org.slf4j.Logger; | |
import org.slf4j.LoggerFactory; | |
@Aspect | |
//Replace "com.package" with your project package | |
public class StatementTracing { | |
static final Logger logger = LoggerFactory.getLogger("jdbc.sql"); | |
@Pointcut("call(* java.sql.Statement.execute*(java.lang.String)) && args(sql) && within(com.package..*)") | |
public void execute(String sql) { | |
} | |
@Pointcut("call(* java.sql.Statement.addBatch(java.lang.String)) && args(sql) && within(com.package..*)") | |
public void addBatch(String sql) { | |
} | |
@Pointcut("call(* java.sql.Connection.prepareCall(java.lang.String)) && args(sql) && within(com.package..*)") | |
public void prepareCall(String sql) { | |
} | |
@Pointcut("execute(sql) || addBatch(sql) || prepareCall(sql)") | |
public void sqlOperation(String sql) { | |
} | |
@Before("sqlOperation(sql)") | |
public void printQuery(String sql) { | |
logger.info(sql); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment