Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GH-5053: avoid log spam for configurations class with legacy settings #5077

Merged
merged 1 commit into from
Aug 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,13 @@ public static Set<Value> getPropertyValues(Model model, Resource subject, IRI pr
var fallbackObjects = model.filter(subject, fallbackProperty, null).objects();

if (!fallbackObjects.isEmpty() && !preferredObjects.equals(fallbackObjects)) {
logger.warn("Discrepancy between use of the old and new config vocabulary.");
var msg = "Discrepancy between use of the old and new config vocabulary.";
// depending on whether preferred is set, we log on warn or debug
if (preferredObjects.isEmpty()) {
logger.debug(msg);
} else {
logger.warn(msg);
}

if (preferredObjects.containsAll(fallbackObjects)) {
return preferredObjects;
Expand Down Expand Up @@ -235,7 +241,13 @@ public static Optional<Resource> getSubjectByType(Model model, IRI type, IRI leg
private static void logDiscrepancyWarning(Optional<? extends Value> preferred,
Optional<? extends Value> fallback) {
if (!fallback.isEmpty() && !preferred.equals(fallback)) {
logger.warn("Discrepancy between use of the old and new config vocabulary.");
var msg = "Discrepancy between use of the old and new config vocabulary.";
// depending on whether preferred is set, we log on warn or debug
if (preferred.isEmpty()) {
logger.debug(msg);
} else {
logger.warn(msg);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ public void testGetLiteralValue_no_discrepancy() {
var result = Configurations.getLiteralValue(m, subject, RDFS.LABEL, RDFS.COMMENT);
assertThat(result).contains(literal("label"));
assertNotLogged("Discrepancy between use of the old and new config vocabulary.", Level.WARN);
assertNotLogged("Discrepancy between use of the old and new config vocabulary.", Level.DEBUG);
}

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

assertThat(result).contains(literal("label"));
assertLogged("Discrepancy between use of the old and new config vocabulary.", Level.WARN);
assertLogged("Discrepancy between use of the old and new config vocabulary.", Level.DEBUG);
}

@Test
public void testGetLiteralValue_onlyLegacy() {

var subject = bnode();
var m = new ModelBuilder().subject(subject)
.add(RDFS.COMMENT, "comment")
.build();

var result = Configurations.getLiteralValue(m, subject, RDFS.LABEL, RDFS.COMMENT);

assertThat(result).contains(literal("comment"));
assertLogged("Discrepancy between use of the old and new config vocabulary.", Level.DEBUG);
}

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

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

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

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

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

@Test
Expand Down
Loading