public final class StatementFormatter extends Object
Statement.
Its main method is the format method. It can format statements with different levels of verbosity, which
in turn determines which elements to include in the formatted string (query string, bound values,
custom payloads, inner statements for batches, etc.).
StatementFormatter also provides safeguards to prevent overwhelming your logs with
large query strings, queries with considerable amounts of parameters, batch queries with several
inner statements, etc.
StatementFormatter is fully customizable. To build a customized formatter, use the
builder() method as follows:
StatementFormatter formatter = StatementFormatter.builder()
// customize formatter settings
.withMaxBoundValues(42)
.build()
It is also possible to take full control over how a specific kind of statement should be
formatted. To do this, simply implement a StatementPrinter:
class MyCustomStatement extends StatementWrapper {...}
class MyCustomStatementPrinter implements StatementPrinter<MyCustomStatement> {
public Class<MyCustomStatement> getSupportedStatementClass() {
return MyCustomStatement.class;
}
public void print(CustomStatement statement, StatementWriter out, StatementFormatVerbosity verbosity) {
// go crazy
}
}
Then add it to the resulting formatter as follows:
StatementFormatter formatter = StatementFormatter.builder()
.addStatementPrinter(new MyCustomStatementPrinter())
.build()
The driver ships with a set of printers that handle all the built-in statement types. It is
possible to completely override them by simply providing a StatementPrinter for the type
of Statement that you wish to override, using the same method outlined above.
Instances of this class are thread-safe.
| Modifier and Type | Class and Description |
|---|---|
static class |
StatementFormatter.Builder
Helper class to build
StatementFormatter instances with a fluent API. |
| Modifier and Type | Method and Description |
|---|---|
static StatementFormatter.Builder |
builder()
Creates a new
StatementFormatter.Builder instance. |
String |
format(Statement<?> statement,
StatementFormatVerbosity verbosity,
ProtocolVersion protocolVersion,
CodecRegistry codecRegistry)
Formats the given
statement. |
public static StatementFormatter.Builder builder()
StatementFormatter.Builder instance.public String format(Statement<?> statement, StatementFormatVerbosity verbosity, ProtocolVersion protocolVersion, CodecRegistry codecRegistry)
statement.statement - The statement to format; must not be null.verbosity - The verbosity to use.protocolVersion - The protocol version in use.codecRegistry - The codec registry in use.Copyright © 2017–2021 DataStax. All rights reserved.