From bfa6b86f9234ba209ee1e2bff3da2f2c1041ccd3 Mon Sep 17 00:00:00 2001 From: Andreas Schwarte Date: Thu, 18 Jul 2024 13:11:13 +0200 Subject: [PATCH] GH-5053: avoid log spam for configurations class with legacy settings When there is only a value for the legacy setting (i.e. the new config setting is not used) we now log on level debug. Otherwise on warn. The rational is: when users still have persisted legacy repository configurations, the log is easily spammed with warnings. --- .../rdf4j/model/util/Configurations.java | 16 ++++++++++++-- .../rdf4j/model/util/ConfigurationsTest.java | 22 ++++++++++++++++++- 2 files changed, 35 insertions(+), 3 deletions(-) diff --git a/core/model/src/main/java/org/eclipse/rdf4j/model/util/Configurations.java b/core/model/src/main/java/org/eclipse/rdf4j/model/util/Configurations.java index 4bb8a37689f..b74e2f84ec4 100644 --- a/core/model/src/main/java/org/eclipse/rdf4j/model/util/Configurations.java +++ b/core/model/src/main/java/org/eclipse/rdf4j/model/util/Configurations.java @@ -165,7 +165,13 @@ public static Set 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; @@ -235,7 +241,13 @@ public static Optional getSubjectByType(Model model, IRI type, IRI leg private static void logDiscrepancyWarning(Optional preferred, Optional 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); + } } } } diff --git a/core/model/src/test/java/org/eclipse/rdf4j/model/util/ConfigurationsTest.java b/core/model/src/test/java/org/eclipse/rdf4j/model/util/ConfigurationsTest.java index 7a57ccb53e3..c0d9e026675 100644 --- a/core/model/src/test/java/org/eclipse/rdf4j/model/util/ConfigurationsTest.java +++ b/core/model/src/test/java/org/eclipse/rdf4j/model/util/ConfigurationsTest.java @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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