Skip to content

Commit d6c34c9

Browse files
committed
Add loggingLevel option
1 parent c863a92 commit d6c34c9

File tree

3 files changed

+33
-0
lines changed

3 files changed

+33
-0
lines changed

Diff for: README.md

+1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ Recognized properties are the following:
3030
* `sslenabled=true/false`
3131
* `meta.sampling.size=<integer>` specifies a number of documents fetched in order to infer a database schema
3232
* `query.scan.consistency=not_bounded/request_plus` specifies a query scan consistency (RYW consistency) [default value is `not_bounded`]
33+
* `loggingLevel` [default value is `severe`]
3334
* Propagated to a Couchbase cluster
3435
* The full list of recognized parameters is documented in the Couchbase [Client-Settings Documentation](https://docs.couchbase.com/java-sdk/current/ref/client-settings.html).
3536
Any client setting with a system property name may also be specified as a connection string parameter (without the com.couchbase.env. prefix).

Diff for: driver/src/main/java/com/intellij/CouchbaseClientURI.java

+26
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@
1010

1111
import java.sql.SQLException;
1212
import java.util.*;
13+
import java.util.logging.ConsoleHandler;
14+
import java.util.logging.Handler;
15+
import java.util.logging.Level;
16+
import java.util.logging.Logger;
1317
import java.util.stream.Collectors;
1418

1519
import static com.intellij.DriverPropertyInfoHelper.*;
@@ -57,6 +61,8 @@ public CouchbaseClientURI(@NotNull String uri, @Nullable Properties info) {
5761
serverPart = serverPart.substring(0, lastSlashIndex);
5862
}
5963

64+
setLoggingLevel(info, options);
65+
6066
this.userName = getOption(info, options, USER, null);
6167
this.password = getOption(info, options, PASSWORD, null);
6268
this.sslEnabled = isTrue(getOption(info, options, ENABLE_SSL, ENABLE_SSL_DEFAULT));
@@ -67,6 +73,26 @@ public CouchbaseClientURI(@NotNull String uri, @Nullable Properties info) {
6773
this.connectionString = createConnectionString(serverPart, options);
6874
}
6975

76+
private void setLoggingLevel(Properties info, Map<String, List<String>> options) {
77+
Logger logger = Logger.getLogger("com.couchbase.client");
78+
String logLevel = getOption(info, options, LOGGING_LEVEL, LOGGING_LEVEL_DEFAULT);
79+
if (logLevel == null) return;
80+
Level level;
81+
try {
82+
level = Level.parse(logLevel.toUpperCase(Locale.ENGLISH));
83+
}
84+
catch (IllegalArgumentException e) {
85+
e.printStackTrace();
86+
return;
87+
}
88+
logger.setLevel(level);
89+
for (Handler h : logger.getParent().getHandlers()) {
90+
if (h instanceof ConsoleHandler) {
91+
h.setLevel(level);
92+
}
93+
}
94+
}
95+
7096
/**
7197
* @return option from properties or from uri if it is not found in properties.
7298
* null if options was not found.

Diff for: driver/src/main/java/com/intellij/DriverPropertyInfoHelper.java

+6
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ public class DriverPropertyInfoHelper {
2727

2828
public static final String DEFAULT_BUCKET = "defaultBucket";
2929

30+
public static final String LOGGING_LEVEL = "loggingLevel";
31+
public static final String LOGGING_LEVEL_DEFAULT = "severe";
32+
private static final String[] LOGGING_LEVEL_CHOICES = new String[]{"off", "severe", "warning", "info", "fine", "all"};
33+
3034

3135
public static DriverPropertyInfo[] getPropertyInfo() {
3236
ArrayList<DriverPropertyInfo> propInfos = new ArrayList<>();
@@ -46,6 +50,8 @@ public static DriverPropertyInfo[] getPropertyInfo() {
4650
"Query scan consistency.",
4751
ScanConsistency.CHOICES);
4852

53+
addPropInfo(propInfos, LOGGING_LEVEL, LOGGING_LEVEL_DEFAULT, "", LOGGING_LEVEL_CHOICES);
54+
4955
return propInfos.toArray(new DriverPropertyInfo[0]);
5056
}
5157

0 commit comments

Comments
 (0)