p6spy
should help here.
In general, following should do the job for you:
- enable
p6spy
in your app (see official docs: http://p6spy.github.io/p6spy/)
afterwards you have basically 2 options:
- use provided:
BatchFileLogger
, enabling it via:appender=com.p6spy.engine.spy.appender.BatchFileLogger
inspy.properties
(it's however undocumented yet, see: https://github.com/p6spy/p6spy/issues/119)
OR
- implement custom
com.p6spy.engine.spy.appender.MessageFormattingStrategy
, that would be returning sql only (see: https://stackoverflow.com/a/23521623/1581069 for idea on implementation) and configure it inspy.properties
via:logMessageFormat=FooFormat
- set
sqlexpression
to match the queries you need - restrictingCREATE/ALTER/... TABLE/SEQUENCE/...
(see official docs: http://p6spy.github.io/p6spy/2.0/configandusage.html)
still there are some tricky points, like:
databaseDialectDateFormat
property (to be able to kind of replay the output without modifications). For inspiration for some of the common databases, see the unit tests of p6spy itself: https://github.com/p6spy/p6spy/tree/master/src/test/resources/com/p6spy/engine/spy