p6spy, create a new log file (with timestamp) at each start

329 Views Asked by At

title say it everything. I want to log my sql queries but the problem is, at each program restart it append query in same file because I'm specifying the same in my spy.properties file:

driverlist=com.mysql.cj.jdbc.Driver
dateformat=yyyy-MM-dd HH:mm:ss.SSSS
appender=com.p6spy.engine.spy.appender.FileLogger
logfile=C:\\Users\\manis\\Documents\\log\\dblog\\spy.log
logMessageFormat=com.p6spy.engine.spy.appender.SingleLineFormat

I want log file to have name something like this: spy_TIMESTAMP.log

I m using JDBC for db connection.

1

There are 1 best solutions below

0
On

P6Spy does not support that functionality out of the box, but one thing you could do is to override values from spy.properties passing system properties -Dp6spy.config.logfile=myuniquefile.log or from the code:

System.setProperty("p6spy.config.logfile", String.format("C:\\Users\\manis\\Documents\\log\\dblog\\spy-%s.log", System.currentTimeMillis()));

but it should happen before JDBC driver initialisation.