You can use
the datasource-proxyIt allows you to log all requests, and if it is not necessary to configure logging only for "heavy" query that run longer than n seconds in time.
The entry in the log looks like this:
Name:MyDS, Time:1, Success:True, Type:Statement, Batch:False, QuerySize:1, BatchSize:0, Query:["CREATE TABLE users (id INT, name VARCHAR(20))"], Params:[] Name:MyDS, Time:0, Success:True, Type:Prepared, Batch:True, QuerySize:1, BatchSize:2, Query:["INSERT INTO users (id, name) VALUES (?, ?)"], Params:[(1=1,2=foo),(1=2,2=bar)] Name:MyDS, Time:1, Success:True, Type:Prepared, Batch:True, QuerySize:1, BatchSize:2, Query:["INSERT INTO users (id, name) VALUES (?, ?)"], Params:[(1=3,2=FOO) (1=4,2=BAR)] Name:MyDS, Time:3, Success:True, Type:Statement, Batch:False, QuerySize:1, BatchSize:0, Query:["SELECT COUNT(*) FROM users"], Params:[]
Examples of configurations and settings can be viewed
here Simple example configuration :
DataSource db = ProxyDataSourceBuilder .create(actualDataSource) .logQueryByCommons(INFO) // or logQueryBySlf4j(INFO) .build();