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 isShowCql();
public abstract boolean showValues();
public abstract PrintStream getPrintStream(); public abstract PrintStream getPrintStream();
public abstract Executor getExecutor(); public abstract Executor getExecutor();

View file

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

View file

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

View file

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