You’ll need to supply your own logger that removes the redacted portions:
LogRedaction.setRedactionLevel(RedactionLevel.PARTIAL);
LoggingEventConsumer.Logger logger = new MySlf4JLogger("com.couchbase");
ClusterEnvironment env = ClusterEnvironment.builder()
.loggerConfig(l -> l.customLogger(logger))
import com.couchbase.client.core.cnc.LoggingEventConsumer;
import com.couchbase.client.core.logging.RedactableArgument;
import com.couchbase.client.core.util.CbCollections;
import org.slf4j.LoggerFactory;
import org.slf4j.MDC;
import java.util.Map;
import java.util.logging.Level;
import java.util.stream.Collectors;
public class MySlf4JLogger implements LoggingEventConsumer.Logger {
private final org.slf4j.Logger logger;
MySlf4JLogger(String name) {
this.logger = LoggerFactory.getLogger(name);
}
public String getName() {
return this.logger.getName();
}
public boolean isTraceEnabled() {
return this.logger.isTraceEnabled();
}
public void trace(String msg) {
this.logger.trace(redact(msg));
}
public void trace(String msg, Throwable t) {
this.logger.trace(redact(msg), t);
}
public boolean isDebugEnabled() {
return this.logger.isDebugEnabled();
}
public void debug(String msg) {
this.logger.debug(redact(msg));
}
public void debug(String msg, Throwable t) {
this.logger.debug(redact(msg), t);
}
public boolean isInfoEnabled() {
return this.logger.isInfoEnabled();
}
public void info(String msg) {
this.logger.info(redact(msg));
}
public void info(String msg, Throwable t) {
this.logger.info(redact(msg), t);
}
public boolean isWarnEnabled() {
return this.logger.isWarnEnabled();
}
public void warn(String msg) {
this.logger.warn(redact(msg));
}
public void warn(String msg, Throwable t) {
this.logger.warn(redact(msg), t);
}
public boolean isErrorEnabled() {
return this.logger.isErrorEnabled();
}
public void error(String msg) {
this.logger.error(redact(msg));
}
public void error(String msg, Throwable t) {
this.logger.error(redact(msg), t);
}
private String redact(String msg){
return msg.replaceAll("<ud>.*</ud>", "<redacted/>");
}
@Override
public void attachContext(Map<String, Object> context) {
if (!CbCollections.isNullOrEmpty(context)) {
MDC.setContextMap((Map)context.entrySet().stream().collect(Collectors.toMap((e) -> {
return RedactableArgument.redactUser(e.getKey()).toString();
}, (e) -> {
Object v = e.getValue();
return v == null ? "" : RedactableArgument.redactUser(v.toString()).toString();
})));
}
}
public void clearContext() {
MDC.clear();
}
public org.slf4j.Logger getImplementation() {
return this.logger;
}
}
If you want to customize your Slf4J logger…
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<appender name="console" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%d %5p %40.40c:%4L - %m%n</pattern>
</encoder>
</appender>
<root level="info">
<appender-ref ref="console"/>
</root>
<logger name="com.couchbase" level="debug"/>"
</configuration>```
2023-04-10 11:41:10,436 DEBUG com.couchbase: 41 - [com.couchbase.request][RequestRetryScheduledEvent] Request QueryRequest retry scheduled per RetryStrategy (Reason: BUCKET_OPEN_IN_PROGRESS) {“cancelled”:true,“completed”:true,“coreId”:“0xf7ae716e00000001”,“idempotent”:false,“reason”:“TIMEOUT”,“requestId”:4,“requestType”:“QueryRequest”,“retried”:1,“retryReasons”:[“BUCKET_OPEN_IN_PROGRESS”],“service”:{“bucket”:“daniel-wucmmh”,“operationId”:“null”,“scope”:“samples”,“statement”:“<redacted/>”,“type”:“query”},“timeoutMs”:1,“timings”:{“totalMicros”:7366}}