Skip to content

Commit fb16f4a

Browse files
author
hideki
committed
Fixed #1028 - Improve logging for local check point conflicted error
- In case of Conflict, should not print stack trace. - Remove `Log.w(Log.TAG_SYNC, "%s: Unable to save remote checkpoint", e, this);`. Detailed log was printed in following codes. - Remove all `Exception.printStackTrace()`. Replace with `Log.e(...)`
1 parent fc011c3 commit fb16f4a

6 files changed

Lines changed: 18 additions & 15 deletions

File tree

src/main/java/com/couchbase/lite/BlobStore.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -654,7 +654,7 @@ public boolean isGZipped(BlobKey key) {
654654
magic = raf.read() & 0xff | ((raf.read() << 8) & 0xff00);
655655
raf.close();
656656
} catch (Throwable e) {
657-
e.printStackTrace(System.err);
657+
Log.e(Log.TAG_BLOB_STORE, "Failed to read from RandomAccessFile", e);
658658
}
659659
}
660660
return magic == GZIPInputStream.GZIP_MAGIC;

src/main/java/com/couchbase/lite/internal/Body.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
package com.couchbase.lite.internal;
1919

2020
import com.couchbase.lite.Manager;
21+
import com.couchbase.lite.util.Log;
2122
import com.fasterxml.jackson.databind.ObjectWriter;
2223

2324
import java.io.IOException;
@@ -61,7 +62,7 @@ public Body(byte[] json, String docID, String revID, boolean deleted) {
6162
try {
6263
props = Manager.getObjectMapper().readValue(json, Map.class);
6364
} catch (IOException e) {
64-
e.printStackTrace();
65+
Log.w(Log.TAG_DATABASE, "Failed to parse Json document", e);
6566
}
6667
props.putAll(extra);
6768
this.object = props;

src/main/java/com/couchbase/lite/replicator/PullerInternal.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -852,7 +852,7 @@ public void run() {
852852
try {
853853
processChangeTrackerStopped(changeTracker);
854854
} catch (RuntimeException e) {
855-
e.printStackTrace();
855+
Log.e(Log.TAG_CHANGE_TRACKER, "Unknown Error in processChangeTrackerStopped()", e);
856856
throw e;
857857
}
858858
}
@@ -1067,13 +1067,13 @@ private void waitPendingFuturesCompleted() {
10671067
while (!pendingFutures.isEmpty()) {
10681068
Future future = pendingFutures.take();
10691069
try {
1070-
Log.d(TAG, "calling future.get() on %s", future);
1070+
Log.v(TAG, "calling future.get() on %s", future);
10711071
future.get();
1072-
Log.d(TAG, "done calling future.get() on %s", future);
1072+
Log.v(TAG, "done calling future.get() on %s", future);
10731073
} catch (InterruptedException e) {
1074-
e.printStackTrace();
1074+
Log.e(Log.TAG_SYNC, "InterruptedException in Future.get()", e);
10751075
} catch (ExecutionException e) {
1076-
e.printStackTrace();
1076+
Log.e(Log.TAG_SYNC, "ExecutionException in Future.get()", e);
10771077
}
10781078
}
10791079
} catch (Exception e) {

src/main/java/com/couchbase/lite/replicator/PusherInternal.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,9 +157,9 @@ public void waitForPendingFutures() {
157157
future.get();
158158
Log.d(Log.TAG_SYNC, "done calling future.get() on %s", future);
159159
} catch (InterruptedException e) {
160-
e.printStackTrace();
160+
Log.e(Log.TAG_SYNC, "InterruptedException in Future.get()", e);
161161
} catch (ExecutionException e) {
162-
e.printStackTrace();
162+
Log.e(Log.TAG_SYNC, "ExecutionException in Future.get()", e);
163163
}
164164
}
165165

src/main/java/com/couchbase/lite/replicator/ReplicationInternal.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ public void run() {
205205
Log.d(Log.TAG_SYNC, "firing trigger: %s", trigger);
206206
stateMachine.fire(trigger);
207207
} catch (Exception e) {
208-
e.printStackTrace();
208+
Log.e(Log.TAG_SYNC, "Unknown Error in stateMachine.fire(trigger)", e);
209209
throw new RuntimeException(e);
210210
}
211211
}
@@ -734,7 +734,6 @@ public void onCompletion(HttpResponse httpResponse, Object result, Throwable e)
734734
try {
735735

736736
if (e != null) {
737-
Log.w(Log.TAG_SYNC, "%s: Unable to save remote checkpoint", e, this);
738737
// Failed to save checkpoint:
739738
switch (Utils.getStatusFromError(e)) {
740739
case Status.NOT_FOUND:
@@ -1111,8 +1110,7 @@ private void notifyChangeListeners(final Replication.ChangeEvent changeEvent) {
11111110
try {
11121111
changeListener.changed(changeEvent);
11131112
} catch (Exception e) {
1114-
e.printStackTrace();
1115-
Log.e(Log.TAG_SYNC, "Exception notifying replication listener: %s", e);
1113+
Log.e(Log.TAG_SYNC, "Unknown Error in changeListener.changed(changeEvent)", e);
11161114
}
11171115
}
11181116
} else {

src/main/java/com/couchbase/lite/router/Router.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1894,8 +1894,12 @@ private RevisionInternal update(Database _db, String docID, Body body, boolean d
18941894
}
18951895

18961896
} catch (CouchbaseLiteException e) {
1897-
e.printStackTrace();
1898-
Log.e(Log.TAG_ROUTER, "Error updating doc: %s", e, docID);
1897+
if (e.getCBLStatus() != null && e.getCBLStatus().getCode() == Status.CONFLICT) {
1898+
// conflict is not critical error for replicators, not print stack trace
1899+
Log.w(Log.TAG_ROUTER, "Error updating doc: %s", docID);
1900+
} else {
1901+
Log.e(Log.TAG_ROUTER, "Error updating doc: %s", e, docID);
1902+
}
18991903
outStatus.setCode(e.getCBLStatus().getCode());
19001904
}
19011905

0 commit comments

Comments
 (0)