Skip to content

Commit

Permalink
feat: Improve Logging (#1892)
Browse files Browse the repository at this point in the history
* feat: Improve logging

* fix formatting
  • Loading branch information
eranl authored Oct 29, 2024
1 parent 9d1698d commit e74457a
Show file tree
Hide file tree
Showing 9 changed files with 52 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -174,4 +174,10 @@ private void consumePartitions(
}
consumer.apply(new QueryPartition(partitionQuery, lastCursor, null));
}

@SuppressWarnings("MethodDoesntCallSuperMethod")
@Override
public String toString() {
return String.format("CollectionGroup{partitionQuery=%s, options=%s}", partitionQuery, options);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -114,4 +114,11 @@ public boolean equals(Object obj) {
public int hashCode() {
return Objects.hash(type, document, oldIndex, newIndex);
}

@Override
public String toString() {
return String.format(
"DocumentChange{type=%s, document=%s, oldIndex=%d, newIndex=%d}",
type, document, oldIndex, newIndex);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -162,4 +162,11 @@ public boolean equals(Object o) {
public int hashCode() {
return Objects.hash(query, this.getDocumentChanges(), this.getDocuments());
}

@Override
public String toString() {
return String.format(
"%s{query=%s, readTime=%s, documentChanges=%s, documents=%s}",
getClass().getSimpleName(), query, readTime, documentChanges, documents);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,11 @@
*/
final class SilenceableBidiStream<RequestT, ResponseT>
implements BidiStreamObserver<RequestT, ResponseT> {
private static final Logger LOGGER = Logger.getLogger(SilenceableBidiStream.class.getName());

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

SilenceableBidiStream(
BidiStreamObserver<RequestT, ResponseT> responseObserverT,
Expand All @@ -63,17 +63,17 @@ public boolean isSilenced() {
}

public void send(RequestT request) {
LOGGER.info(stream.toString());
LOGGER.fine(stream.toString());
stream.send(request);
}

public void closeSend() {
LOGGER.info(stream::toString);
LOGGER.fine(stream::toString);
stream.closeSend();
}

public void closeSendAndSilence() {
LOGGER.info(stream::toString);
LOGGER.fine(stream::toString);
silence = true;
stream.closeSend();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -397,4 +397,9 @@ private boolean isRetryableError(Throwable throwable, Set<StatusCode.Code> retry
}
return false;
}

@Override
public String toString() {
return String.format("%s{options=%s}", getClass().getSimpleName(), options);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,14 @@ VectorQuerySnapshot createSnaphot(
return VectorQuerySnapshot.withDocuments(this, readTime, documents);
}

@SuppressWarnings("MethodDoesntCallSuperMethod")
@Override
public String toString() {
return String.format(
"VectorQuery{query=%s, vectorField=%s, queryVector=%s, limit=%d, distanceMeasure=%s, options=%s, options=%s}",
query, vectorField, queryVector, limit, distanceMeasure, options, options);
}

/**
* The distance measure to use when comparing vectors in a {@link VectorQuery}.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,13 @@ public boolean equals(Object obj) {
&& Objects.equals(distanceThreshold, otherOptions.distanceThreshold);
}

@Override
public String toString() {
return String.format(
"VectorQueryOptions{distanceResultField=%s, distanceThreshold=%s}",
distanceResultField, distanceThreshold);
}

/** Default VectorQueryOptions instance. */
private static VectorQueryOptions DEFAULT = newBuilder().build();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,9 @@ MapValue toProto() {
int size() {
return this.values.length;
}

@Override
public String toString() {
return String.format("VectorValue{values=%s}", Arrays.toString(values));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@
* synchronization.
*/
final class Watch implements BidiStreamObserver<ListenRequest, ListenResponse> {
private static final Logger LOGGER = Logger.getLogger(Watch.class.getName());

/**
* Target ID used by watch. Watch uses a fixed target id since we only support one target per
* stream. The actual target ID we use is arbitrary.
Expand Down Expand Up @@ -115,8 +117,6 @@ static class ChangeSet {
List<QueryDocumentSnapshot> updates = new ArrayList<>();
}

private static final Logger LOGGER = Logger.getLogger(Watch.class.getName());

/**
* @param firestore The Firestore Database client.
* @param query The query that is used to order the document snapshots returned by this watch.
Expand Down Expand Up @@ -474,7 +474,7 @@ private void pushSnapshot(final Timestamp readTime, ByteString nextResumeToken)
if (!hasPushed || !changes.isEmpty()) {
final QuerySnapshot querySnapshot =
QuerySnapshot.withChanges(query, readTime, documentSet, changes);
LOGGER.info(querySnapshot.toString());
LOGGER.fine(querySnapshot.toString());
userCallbackExecutor.execute(() -> listener.onEvent(querySnapshot, null));
hasPushed = true;
}
Expand Down

0 comments on commit e74457a

Please sign in to comment.