Skip to content

Commit 2e64c48

Browse files
committed
* mongo: fixed MongoCollection.aggregate() pipeline logging
Signed-off-by: neo <[email protected]>
1 parent 57def5d commit 2e64c48

File tree

3 files changed

+44
-3
lines changed

3 files changed

+44
-3
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
* ws: remove ws support
1010
> websocket is not used anymore, use sse/ajax instead
1111
* kafka: updated to 4.0.0
12+
* mongo: fixed MongoCollection.aggregate() pipeline logging
1213

1314
### 9.1.7 (2/26/2025 - 3/6/2025)
1415

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package core.framework.mongo.impl;
2+
3+
import core.framework.internal.log.filter.LogParam;
4+
import org.bson.codecs.configuration.CodecRegistry;
5+
import org.bson.conversions.Bson;
6+
7+
import java.util.List;
8+
import java.util.Set;
9+
10+
/**
11+
* @author neo
12+
*/
13+
class BsonsLogParam implements LogParam {
14+
private final List<Bson> bsons;
15+
private final CodecRegistry registry;
16+
17+
BsonsLogParam(List<Bson> bsons, CodecRegistry registry) {
18+
this.bsons = bsons;
19+
this.registry = registry;
20+
}
21+
22+
@Override
23+
public void append(StringBuilder builder, Set<String> maskedFields, int maxParamLength) {
24+
builder.append('[');
25+
boolean first = true;
26+
for (Bson bson : bsons) {
27+
if (first) {
28+
first = false;
29+
} else {
30+
builder.append(", ");
31+
}
32+
new BsonLogParam(bson, registry)
33+
.append(builder, maskedFields, maxParamLength);
34+
}
35+
builder.append(']');
36+
}
37+
}

core-ng-mongo/src/main/java/core/framework/mongo/impl/MongoCollectionImpl.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636
import java.util.Optional;
3737
import java.util.concurrent.TimeUnit;
3838
import java.util.function.Consumer;
39-
import java.util.stream.Collectors;
4039

4140
/**
4241
* @author neo
@@ -229,7 +228,7 @@ public <V> List<V> aggregate(Aggregate<V> aggregate) {
229228
int size = results.size();
230229
logger.debug("aggregate, collection={}, pipeline={}, readPref={}, returnedDocs={}, elapsed={}",
231230
collectionName,
232-
aggregate.pipeline.stream().map(stage -> new BsonLogParam(stage, mongo.registry)).collect(Collectors.toList()),
231+
new BsonsLogParam(aggregate.pipeline, mongo.registry),
233232
aggregate.readPreference == null ? null : aggregate.readPreference.getName(),
234233
size,
235234
elapsed);
@@ -320,7 +319,11 @@ public long delete(Bson filter) {
320319
return deletedRows;
321320
} finally {
322321
long elapsed = watch.elapsed();
323-
logger.debug("delete, collection={}, filter={}, deletedRows={}, elapsed={}", collectionName, new BsonLogParam(filter, mongo.registry), deletedRows, elapsed);
322+
logger.debug("delete, collection={}, filter={}, deletedRows={}, elapsed={}",
323+
collectionName,
324+
new BsonLogParam(filter, mongo.registry),
325+
deletedRows,
326+
elapsed);
324327
ActionLogContext.track("mongo", elapsed, 0, (int) deletedRows);
325328
}
326329
}

0 commit comments

Comments
 (0)