Reputation: 1
I'm trying to use p6spy for logging outage sql-statement. Based on official doc (http://p6spy.readthedocs.io/en/latest/index.html) I can do it by set specific properties in spy.properties file such as outagedetection and outagedetectioninterval. I set outagedetection value in 'true' and outagedetectioninterval in '1' and I thought that I saw only the statements with execution time more than 1 second in my result spy.log file, but I got unexpected result :( - I saw all sql-statement in spite of outage-properties I've set. Has anybody faced with such problem?
We use hibernate 5 + spring boot + h2 db + maven. For using p6spy i've done the following configuration.
Add dependency in pom.xml enter image description here
In official doc of p6spy (http://p6spy.readthedocs.io/en/latest/configandusage.html#common-property-file-settings) i got the spy.property and leave only the properties i needed. The result in the code below (i deleted some commented lines for readability): enter image description here
Changed my application.yml next way:
Upvotes: 0
Views: 770
Reputation: 1
Thank you, your advice has helped me. But still there is an issue which I haven't already understood. For logging sql-statement I must have an instance P6LogOptions.class. If I set a 'com.p6spy.engine.logging.P6LogFactory' as a value of 'modulelist' property, the instance of P6LogOptions.class is created in overriden getOptions(...) method (this method is declared in P6Factory interface). In the case of 'com.p6spy.engine.outage.P6OutageFactory' as a value of 'modulelist' property we haven't got an instance of P6LogOptions.class and in this case I've faced with NPE exception.
Exception in thread "P6SpyOutageThread" java.lang.NullPointerException
at com.p6spy.engine.common.P6LogQuery.isLoggable(P6LogQuery.java:148)
at com.p6spy.engine.common.P6LogQuery.logElapsed(P6LogQuery.java:188)
at com.p6spy.engine.outage.P6OutageDetector.logOutage(P6OutageDetector.java:142)
at com.p6spy.engine.outage.P6OutageDetector.detectOutage(P6OutageDetector.java:136)
at com.p6spy.engine.outage.P6OutageDetector.run(P6OutageDetector.java:78)
at java.lang.Thread.run(Thread.java:748)
I've resolved this exception by creating in my project one more factory which implements P6Factory.class. The code of the new class below:
public class LogFactory implements P6Factory {
@Override
public P6LoadableOptions getOptions(P6OptionsRepository optionsRepository) {
return new P6LogOptions(optionsRepository);
}
@Override
public JdbcEventListener getJdbcEventListener() {
return new JdbcEventListener() {
// NOOP
};
}
}
In my opinion such behaviour a little strange. I suppose to use 'modulelist' property with 'com.p6spy.engine.outage.P6OutageFactory' value without creating additional classes.
For correct using of p6spy lib I've found 2 variants:
Upvotes: 0
Reputation: 231
You need to remove com.p6spy.engine.logging.P6LogFactory
from modulelist
property.
Also for easier configuration you can use my library, that I've created for integration with spring-boot. It allows easier configuration for most of spy.properties
using application.yml
.
Upvotes: 0