Enable toggle for showing values in logged CQL statements. Default to true.

This commit is contained in:
Greg Burd 2017-11-12 22:32:58 -05:00
parent 39a8643103
commit a993af6c29
4 changed files with 37 additions and 1 deletions

View file

@ -42,6 +42,8 @@ public abstract class AbstractSessionOperations {
public abstract boolean isShowCql();
public abstract boolean showValues();
public abstract PrintStream getPrintStream();
public abstract Executor getExecutor();

View file

@ -74,12 +74,14 @@ public class HelenusSession extends AbstractSessionOperations implements Closeab
private final Metadata metadata;
private volatile String usingKeyspace;
private volatile boolean showCql;
private volatile boolean showValues;
HelenusSession(
Session session,
String usingKeyspace,
CodecRegistry registry,
boolean showCql,
boolean showValues,
PrintStream printStream,
SessionRepositoryBuilder sessionRepositoryBuilder,
Executor executor,
@ -96,6 +98,7 @@ public class HelenusSession extends AbstractSessionOperations implements Closeab
Objects.requireNonNull(
usingKeyspace, "keyspace needs to be selected before creating session");
this.showCql = showCql;
this.showValues = showValues;
this.printStream = printStream;
this.sessionRepository = sessionRepositoryBuilder.build();
this.executor = executor;
@ -153,6 +156,20 @@ public class HelenusSession extends AbstractSessionOperations implements Closeab
return this;
}
public HelenusSession showQueryValuesInLog(boolean showValues) {
this.showValues = showValues;
return this;
}
public HelenusSession showQueryValuesInLog() {
this.showValues = true;
return this;
}
public boolean showValues() {
return showValues;
}
@Override
public Executor getExecutor() {
return executor;

View file

@ -43,6 +43,7 @@ public final class SessionInitializer extends AbstractSessionOperations {
private CodecRegistry registry;
private String usingKeyspace;
private boolean showCql = false;
private boolean showValues = true;
private ConsistencyLevel consistencyLevel;
private boolean idempotent = true;
private MetricRegistry metricRegistry = new MetricRegistry();
@ -103,6 +104,20 @@ public final class SessionInitializer extends AbstractSessionOperations {
return this;
}
public SessionInitializer showQueryValuesInLog(boolean showValues) {
this.showValues = showValues;
return this;
}
public SessionInitializer showQueryValuesInLog() {
this.showValues = true;
return this;
}
public boolean showValues() {
return showValues;
}
public SessionInitializer metricRegistry(MetricRegistry metricRegistry) {
this.metricRegistry = metricRegistry;
return this;
@ -255,6 +270,7 @@ public final class SessionInitializer extends AbstractSessionOperations {
usingKeyspace,
registry,
showCql,
showValues,
printStream,
sessionRepository,
executor,

View file

@ -42,7 +42,7 @@ public abstract class Operation<E> {
private static final Logger LOG = LoggerFactory.getLogger(Operation.class);
protected final AbstractSessionOperations sessionOps;
protected boolean showValues = false;
protected boolean showValues;
protected TraceContext traceContext;
protected long queryExecutionTimeout = 10;
protected TimeUnit queryTimeoutUnits = TimeUnit.SECONDS;
@ -56,6 +56,7 @@ public abstract class Operation<E> {
Operation(AbstractSessionOperations sessionOperations) {
this.sessionOps = sessionOperations;
this.showValues = sessionOps.showValues();
MetricRegistry metrics = sessionOperations.getMetricRegistry();
if (metrics == null) {
metrics = new MetricRegistry();