Skip to content

Commit 1044c5c

Browse files
authored
GH-5053: avoid log spam for configurations class with legacy settings (#5077)
2 parents 59eba18 + bfa6b86 commit 1044c5c

2 files changed

Lines changed: 35 additions & 3 deletions

File tree

core/model/src/main/java/org/eclipse/rdf4j/model/util/Configurations.java

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,13 @@ public static Set<Value> getPropertyValues(Model model, Resource subject, IRI pr
165165
var fallbackObjects = model.filter(subject, fallbackProperty, null).objects();
166166

167167
if (!fallbackObjects.isEmpty() && !preferredObjects.equals(fallbackObjects)) {
168-
logger.warn("Discrepancy between use of the old and new config vocabulary.");
168+
var msg = "Discrepancy between use of the old and new config vocabulary.";
169+
// depending on whether preferred is set, we log on warn or debug
170+
if (preferredObjects.isEmpty()) {
171+
logger.debug(msg);
172+
} else {
173+
logger.warn(msg);
174+
}
169175

170176
if (preferredObjects.containsAll(fallbackObjects)) {
171177
return preferredObjects;
@@ -235,7 +241,13 @@ public static Optional<Resource> getSubjectByType(Model model, IRI type, IRI leg
235241
private static void logDiscrepancyWarning(Optional<? extends Value> preferred,
236242
Optional<? extends Value> fallback) {
237243
if (!fallback.isEmpty() && !preferred.equals(fallback)) {
238-
logger.warn("Discrepancy between use of the old and new config vocabulary.");
244+
var msg = "Discrepancy between use of the old and new config vocabulary.";
245+
// depending on whether preferred is set, we log on warn or debug
246+
if (preferred.isEmpty()) {
247+
logger.debug(msg);
248+
} else {
249+
logger.warn(msg);
250+
}
239251
}
240252
}
241253
}

core/model/src/test/java/org/eclipse/rdf4j/model/util/ConfigurationsTest.java

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ public void testGetLiteralValue_no_discrepancy() {
101101
var result = Configurations.getLiteralValue(m, subject, RDFS.LABEL, RDFS.COMMENT);
102102
assertThat(result).contains(literal("label"));
103103
assertNotLogged("Discrepancy between use of the old and new config vocabulary.", Level.WARN);
104+
assertNotLogged("Discrepancy between use of the old and new config vocabulary.", Level.DEBUG);
104105
}
105106

106107
@Test
@@ -116,7 +117,21 @@ public void testGetLiteralValue_useLegacy_onlyNew() {
116117
System.setProperty("org.eclipse.rdf4j.model.vocabulary.useLegacyConfig", "");
117118

118119
assertThat(result).contains(literal("label"));
119-
assertLogged("Discrepancy between use of the old and new config vocabulary.", Level.WARN);
120+
assertLogged("Discrepancy between use of the old and new config vocabulary.", Level.DEBUG);
121+
}
122+
123+
@Test
124+
public void testGetLiteralValue_onlyLegacy() {
125+
126+
var subject = bnode();
127+
var m = new ModelBuilder().subject(subject)
128+
.add(RDFS.COMMENT, "comment")
129+
.build();
130+
131+
var result = Configurations.getLiteralValue(m, subject, RDFS.LABEL, RDFS.COMMENT);
132+
133+
assertThat(result).contains(literal("comment"));
134+
assertLogged("Discrepancy between use of the old and new config vocabulary.", Level.DEBUG);
120135
}
121136

122137
@Test
@@ -158,6 +173,7 @@ public void testGetResourceValue_no_discrepancy() {
158173
var result = Configurations.getResourceValue(m, subject, RDFS.LABEL, RDFS.COMMENT);
159174
assertThat(result).contains(iri("urn:label"));
160175
assertNotLogged("Discrepancy between use of the old and new config vocabulary.", Level.WARN);
176+
assertNotLogged("Discrepancy between use of the old and new config vocabulary.", Level.DEBUG);
161177
}
162178

163179
@Test
@@ -183,6 +199,7 @@ public void testGetIRIValue_no_discrepancy() {
183199
var result = Configurations.getIRIValue(m, subject, RDFS.LABEL, RDFS.COMMENT);
184200
assertThat(result).contains(iri("urn:label"));
185201
assertNotLogged("Discrepancy between use of the old and new config vocabulary.", Level.WARN);
202+
assertNotLogged("Discrepancy between use of the old and new config vocabulary.", Level.DEBUG);
186203
}
187204

188205
@Test
@@ -197,6 +214,7 @@ public void testGetPropertyValues_no_legacy() {
197214
var result = Configurations.getPropertyValues(m, subject, RDFS.LABEL, RDFS.COMMENT);
198215
assertThat(result).hasSize(2);
199216
assertNotLogged("Discrepancy between use of the old and new config vocabulary.", Level.WARN);
217+
assertNotLogged("Discrepancy between use of the old and new config vocabulary.", Level.DEBUG);
200218
}
201219

202220
@Test
@@ -213,6 +231,7 @@ public void testGetPropertyValues_no_discrepancy() {
213231
var result = Configurations.getPropertyValues(m, subject, RDFS.LABEL, RDFS.COMMENT);
214232
assertThat(result).hasSize(2);
215233
assertNotLogged("Discrepancy between use of the old and new config vocabulary.", Level.WARN);
234+
assertNotLogged("Discrepancy between use of the old and new config vocabulary.", Level.DEBUG);
216235
}
217236

218237
@Test
@@ -229,6 +248,7 @@ public void testGetPropertyValues_useLegacy_no_discrepancy() {
229248
var result = Configurations.getPropertyValues(m, subject, RDFS.LABEL, RDFS.COMMENT);
230249
assertThat(result).hasSize(2);
231250
assertNotLogged("Discrepancy between use of the old and new config vocabulary.", Level.WARN);
251+
assertNotLogged("Discrepancy between use of the old and new config vocabulary.", Level.DEBUG);
232252
}
233253

234254
@Test

0 commit comments

Comments
 (0)