1

Good afternoon! I need to create functionality that would allow me to measure the start/end time and duration of the query. I tried using the log4j library and creating my own logger, but I can't specify it in applicationSpringContext. Maybe someone could advise how to approach this issue correctly ? And what tools could I use for such tasks? Thank you very much for your help! MyLogger:

package net.proselyte.springbootdemo;

import org.hibernate.engine.internal.StatisticalLoggingSessionEventListener;
import org.jboss.logging.Logger;

public class NewStatisticalLoggingSessionEventListener extends StatisticalLoggingSessionEventListener {
    private static final Logger log = Logger.getLogger(NewStatisticalLoggingSessionEventListener.class);

    @Override
    public void jdbcExecuteStatementStart() {
        //Write method
    }

    @Override
    public void jdbcPrepareStatementEnd() {
        //Write method
    }
}

MyApplicationContext when i try to add:

logging.level.net.proselyte.springbootdemo.NewStatisticalLoggingSessionEventListener=info

my task should have this output :

startTime=2020-09-18 Time 10:30:1231
endTime=2020-09-18 Time 10:30:2500
requestExecutionTime=60;
success/unsuccess
Dzhav123
  • 11
  • 1

1 Answers1

0

You could use the following:

long startTime = System.currentTimeMillis();
// Some JDBC call
long finishTime = System.currentTimeMillis();
long timeElapsed = finish - start;
J.Johnson
  • 1
  • 2
  • there are many methods, and if I call start() stop () on each one, it will take a long time. I need a universal option – Dzhav123 Nov 18 '20 at 22:20
  • I have seen technologies like New Relic which can do that but here's a library called " log4jdbc". You can refer [here](https://stackoverflow.com/questions/17988231/how-to-log-jdbc-connection-activity) – J.Johnson Nov 19 '20 at 19:58