From 6353c32b0a17f1af8ddc7edec2d853efee97f789 Mon Sep 17 00:00:00 2001 From: Jeremy Landis Date: Fri, 5 Apr 2024 19:53:29 -0400 Subject: [PATCH] [logging] Make sure we use appropriate logger slf4j 1.7.36 ** ** Because we only use this with maven and to be in line with maven, use 1.7.36 since that is what maven is still using. --- pom.xml | 29 ++++++++++++++++++- .../xml/lib/XmlDocumentFormatter.java | 16 ++++++---- 2 files changed, 39 insertions(+), 6 deletions(-) diff --git a/pom.xml b/pom.xml index aaf4030..43429d8 100644 --- a/pom.xml +++ b/pom.xml @@ -8,7 +8,7 @@ SPDX-License-Identifier: EPL-2.0 --> - + 4.0.0 net.revelc.code @@ -49,4 +49,31 @@ SPDX-License-Identifier: EPL-2.0 true + + + org.slf4j + slf4j-api + 1.7.36 + + + org.slf4j + slf4j-simple + 1.7.36 + test + + + + + + org.apache.maven.plugins + maven-dependency-plugin + + + + org.slf4j:slf4j-simple + + + + + diff --git a/src/main/java/net/revelc/code/formatter/xml/lib/XmlDocumentFormatter.java b/src/main/java/net/revelc/code/formatter/xml/lib/XmlDocumentFormatter.java index 974e6e2..5dbf4d9 100644 --- a/src/main/java/net/revelc/code/formatter/xml/lib/XmlDocumentFormatter.java +++ b/src/main/java/net/revelc/code/formatter/xml/lib/XmlDocumentFormatter.java @@ -17,6 +17,8 @@ import javax.xml.XMLConstants; import javax.xml.parsers.SAXParser; import javax.xml.parsers.SAXParserFactory; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.xml.sax.ErrorHandler; import org.xml.sax.InputSource; import org.xml.sax.SAXException; @@ -25,6 +27,8 @@ public class XmlDocumentFormatter { + private static final Logger logger = LoggerFactory.getLogger(XmlDocumentFormatter.class); + private final String fDefaultLineDelimiter; private final FormattingPreferences prefs; @@ -109,7 +113,8 @@ public String format(String documentText) { } reader.close(); } catch (IOException e) { - System.out.println(e.getMessage()); + logger.error("{}", e.getMessage()); + logger.debug("", e); } return state.out.toString(); } @@ -129,12 +134,13 @@ private void validateWellFormedness(String documentText) { XMLReader reader = parser.getXMLReader(); reader.setErrorHandler(errorHandler); reader.parse(new InputSource(new StringReader(documentText))); - } catch (Exception exception) { - if (!(exception instanceof SAXParseException) + } catch (Exception e) { + if (!(e instanceof SAXParseException) || !prefs.getWellFormedValidation().equals(FormattingPreferences.WARN)) { - throw new IllegalArgumentException(exception); + throw new IllegalArgumentException(e); } - System.err.println("WARN: " + exception.getMessage()); + logger.error("WARN: {}", e.getMessage()); + logger.debug("", e); } }