Skip to content

Commit e74457a

Browse files
authoredOct 29, 2024··
feat: Improve Logging (#1892)
* feat: Improve logging * fix formatting
1 parent 9d1698d commit e74457a

9 files changed

+52
-7
lines changed
 

‎google-cloud-firestore/src/main/java/com/google/cloud/firestore/CollectionGroup.java

+6
Original file line numberDiff line numberDiff line change
@@ -174,4 +174,10 @@ private void consumePartitions(
174174
}
175175
consumer.apply(new QueryPartition(partitionQuery, lastCursor, null));
176176
}
177+
178+
@SuppressWarnings("MethodDoesntCallSuperMethod")
179+
@Override
180+
public String toString() {
181+
return String.format("CollectionGroup{partitionQuery=%s, options=%s}", partitionQuery, options);
182+
}
177183
}

‎google-cloud-firestore/src/main/java/com/google/cloud/firestore/DocumentChange.java

+7
Original file line numberDiff line numberDiff line change
@@ -114,4 +114,11 @@ public boolean equals(Object obj) {
114114
public int hashCode() {
115115
return Objects.hash(type, document, oldIndex, newIndex);
116116
}
117+
118+
@Override
119+
public String toString() {
120+
return String.format(
121+
"DocumentChange{type=%s, document=%s, oldIndex=%d, newIndex=%d}",
122+
type, document, oldIndex, newIndex);
123+
}
117124
}

‎google-cloud-firestore/src/main/java/com/google/cloud/firestore/GenericQuerySnapshot.java

+7
Original file line numberDiff line numberDiff line change
@@ -162,4 +162,11 @@ public boolean equals(Object o) {
162162
public int hashCode() {
163163
return Objects.hash(query, this.getDocumentChanges(), this.getDocuments());
164164
}
165+
166+
@Override
167+
public String toString() {
168+
return String.format(
169+
"%s{query=%s, readTime=%s, documentChanges=%s, documents=%s}",
170+
getClass().getSimpleName(), query, readTime, documentChanges, documents);
171+
}
165172
}

‎google-cloud-firestore/src/main/java/com/google/cloud/firestore/SilenceableBidiStream.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,11 @@
4545
*/
4646
final class SilenceableBidiStream<RequestT, ResponseT>
4747
implements BidiStreamObserver<RequestT, ResponseT> {
48+
private static final Logger LOGGER = Logger.getLogger(SilenceableBidiStream.class.getName());
4849

4950
private final ClientStream<RequestT> stream;
5051
private final BidiStreamObserver<RequestT, ResponseT> delegate;
5152
private boolean silence = false;
52-
private static final Logger LOGGER = Logger.getLogger(Watch.class.getName());
5353

5454
SilenceableBidiStream(
5555
BidiStreamObserver<RequestT, ResponseT> responseObserverT,
@@ -63,17 +63,17 @@ public boolean isSilenced() {
6363
}
6464

6565
public void send(RequestT request) {
66-
LOGGER.info(stream.toString());
66+
LOGGER.fine(stream.toString());
6767
stream.send(request);
6868
}
6969

7070
public void closeSend() {
71-
LOGGER.info(stream::toString);
71+
LOGGER.fine(stream::toString);
7272
stream.closeSend();
7373
}
7474

7575
public void closeSendAndSilence() {
76-
LOGGER.info(stream::toString);
76+
LOGGER.fine(stream::toString);
7777
silence = true;
7878
stream.closeSend();
7979
}

‎google-cloud-firestore/src/main/java/com/google/cloud/firestore/StreamableQuery.java

+5
Original file line numberDiff line numberDiff line change
@@ -397,4 +397,9 @@ private boolean isRetryableError(Throwable throwable, Set<StatusCode.Code> retry
397397
}
398398
return false;
399399
}
400+
401+
@Override
402+
public String toString() {
403+
return String.format("%s{options=%s}", getClass().getSimpleName(), options);
404+
}
400405
}

‎google-cloud-firestore/src/main/java/com/google/cloud/firestore/VectorQuery.java

+8
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,14 @@ VectorQuerySnapshot createSnaphot(
171171
return VectorQuerySnapshot.withDocuments(this, readTime, documents);
172172
}
173173

174+
@SuppressWarnings("MethodDoesntCallSuperMethod")
175+
@Override
176+
public String toString() {
177+
return String.format(
178+
"VectorQuery{query=%s, vectorField=%s, queryVector=%s, limit=%d, distanceMeasure=%s, options=%s, options=%s}",
179+
query, vectorField, queryVector, limit, distanceMeasure, options, options);
180+
}
181+
174182
/**
175183
* The distance measure to use when comparing vectors in a {@link VectorQuery}.
176184
*

‎google-cloud-firestore/src/main/java/com/google/cloud/firestore/VectorQueryOptions.java

+7
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,13 @@ public boolean equals(Object obj) {
148148
&& Objects.equals(distanceThreshold, otherOptions.distanceThreshold);
149149
}
150150

151+
@Override
152+
public String toString() {
153+
return String.format(
154+
"VectorQueryOptions{distanceResultField=%s, distanceThreshold=%s}",
155+
distanceResultField, distanceThreshold);
156+
}
157+
151158
/** Default VectorQueryOptions instance. */
152159
private static VectorQueryOptions DEFAULT = newBuilder().build();
153160

‎google-cloud-firestore/src/main/java/com/google/cloud/firestore/VectorValue.java

+5
Original file line numberDiff line numberDiff line change
@@ -76,4 +76,9 @@ MapValue toProto() {
7676
int size() {
7777
return this.values.length;
7878
}
79+
80+
@Override
81+
public String toString() {
82+
return String.format("VectorValue{values=%s}", Arrays.toString(values));
83+
}
7984
}

‎google-cloud-firestore/src/main/java/com/google/cloud/firestore/Watch.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@
6060
* synchronization.
6161
*/
6262
final class Watch implements BidiStreamObserver<ListenRequest, ListenResponse> {
63+
private static final Logger LOGGER = Logger.getLogger(Watch.class.getName());
64+
6365
/**
6466
* Target ID used by watch. Watch uses a fixed target id since we only support one target per
6567
* stream. The actual target ID we use is arbitrary.
@@ -115,8 +117,6 @@ static class ChangeSet {
115117
List<QueryDocumentSnapshot> updates = new ArrayList<>();
116118
}
117119

118-
private static final Logger LOGGER = Logger.getLogger(Watch.class.getName());
119-
120120
/**
121121
* @param firestore The Firestore Database client.
122122
* @param query The query that is used to order the document snapshots returned by this watch.
@@ -474,7 +474,7 @@ private void pushSnapshot(final Timestamp readTime, ByteString nextResumeToken)
474474
if (!hasPushed || !changes.isEmpty()) {
475475
final QuerySnapshot querySnapshot =
476476
QuerySnapshot.withChanges(query, readTime, documentSet, changes);
477-
LOGGER.info(querySnapshot.toString());
477+
LOGGER.fine(querySnapshot.toString());
478478
userCallbackExecutor.execute(() -> listener.onEvent(querySnapshot, null));
479479
hasPushed = true;
480480
}

0 commit comments

Comments
 (0)
Please sign in to comment.