Skip to content

Commit 46a4317

Browse files
author
Kirill Marchuk
committed
added parameter bind logging
closes #278
1 parent 83ffd14 commit 46a4317

File tree

3 files changed

+26
-0
lines changed

3 files changed

+26
-0
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -478,6 +478,7 @@ Logging facilities:
478478

479479
* Driver Logging (`io.r2dbc.postgresql`)
480480
* Query Logging (`io.r2dbc.postgresql.QUERY` on `DEBUG` level)
481+
* Parameters' values Logging (`io.r2dbc.postgresql.PARAM` on `DEBUG` level)
481482
* Transport Logging (`io.r2dbc.postgresql.client`)
482483
* `DEBUG` enables `Message` exchange logging
483484
* `TRACE` enables traffic logging
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package io.r2dbc.postgresql;
2+
3+
import reactor.util.Logger;
4+
import reactor.util.Loggers;
5+
6+
/**
7+
* Binding logger to log parameter bindings
8+
*/
9+
public final class BindingLogger {
10+
11+
private static final Logger BINDING_LOGGER = Loggers.getLogger("io.r2dbc.postgresql.PARAM");
12+
13+
static void logBinding(int index, String bindValue) {
14+
BINDING_LOGGER.debug("Parameter {} value bound: {}", index, bindValue);
15+
}
16+
17+
static void logBinding(String name, String bindValue) {
18+
BINDING_LOGGER.debug("Parameter {} value bound: {}", name, bindValue);
19+
}
20+
}

src/main/java/io/r2dbc/postgresql/ExtendedQueryPostgresqlStatement.java

+5
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import java.util.Arrays;
3232
import java.util.HashSet;
3333
import java.util.List;
34+
import java.util.Objects;
3435
import java.util.Set;
3536
import java.util.function.Predicate;
3637
import java.util.regex.Matcher;
@@ -74,13 +75,15 @@ public ExtendedQueryPostgresqlStatement bind(String identifier, Object value) {
7475
Assert.requireNonNull(identifier, "identifier must not be null");
7576
Assert.requireType(identifier, String.class, "identifier must be a String");
7677

78+
BindingLogger.logBinding(identifier, Objects.toString(value));
7779
return bind(getIndex(identifier), value);
7880
}
7981

8082
@Override
8183
public ExtendedQueryPostgresqlStatement bind(int index, Object value) {
8284
Assert.requireNonNull(value, "value must not be null");
8385

86+
BindingLogger.logBinding(index, Objects.toString(value));
8487
this.bindings.getCurrent().add(index, this.context.getCodecs().encode(value));
8588

8689
return this;
@@ -92,6 +95,7 @@ public ExtendedQueryPostgresqlStatement bindNull(String identifier, Class<?> typ
9295
Assert.requireType(identifier, String.class, "identifier must be a String");
9396
Assert.requireNonNull(type, "type must not be null");
9497

98+
BindingLogger.logBinding(identifier, "null of type " + type.getName());
9599
bindNull(getIndex(identifier), type);
96100
return this;
97101
}
@@ -100,6 +104,7 @@ public ExtendedQueryPostgresqlStatement bindNull(String identifier, Class<?> typ
100104
public ExtendedQueryPostgresqlStatement bindNull(int index, Class<?> type) {
101105
Assert.requireNonNull(type, "type must not be null");
102106

107+
BindingLogger.logBinding(index, "null of type " + type.getName());
103108
this.bindings.getCurrent().add(index, this.context.getCodecs().encodeNull(type));
104109
return this;
105110
}

0 commit comments

Comments
 (0)