Skip to content

Commit f8a8599

Browse files
committedDec 2, 2024··
better logging
1 parent 6e5f5f3 commit f8a8599

File tree

1 file changed

+24
-8
lines changed

1 file changed

+24
-8
lines changed
 

‎src/main/java/com/jcabi/xml/StrictXML.java

+24-8
Original file line numberDiff line numberDiff line change
@@ -188,18 +188,34 @@ private static Iterable<String> print(
188188
final Collection<SAXParseException> errors) {
189189
final Collection<String> lines = new ArrayList<>(errors.size());
190190
for (final SAXParseException error : errors) {
191-
lines.add(
192-
String.format(
193-
"%d:%d: %s",
194-
error.getLineNumber(),
195-
error.getColumnNumber(),
196-
error.getMessage()
197-
)
198-
);
191+
lines.add(StrictXML.asMessage(error));
199192
}
200193
return lines;
201194
}
202195

196+
/**
197+
* Turn violation into a message.
198+
* @param violation The violation
199+
* @return The message
200+
*/
201+
private static String asMessage(final SAXParseException violation) {
202+
final StringBuilder msg = new StringBuilder(100);
203+
if (violation.getLineNumber() >= 0) {
204+
msg.append('#').append(violation.getLineNumber());
205+
if (violation.getColumnNumber() >= 0) {
206+
msg.append(':').append(violation.getColumnNumber());
207+
}
208+
msg.append(' ');
209+
}
210+
msg.append(violation.getLocalizedMessage());
211+
if (violation.getException() != null) {
212+
msg.append(" (")
213+
.append(violation.getException().getClass().getSimpleName())
214+
.append(')');
215+
}
216+
return msg.toString();
217+
}
218+
203219
/**
204220
* Joins many objects' string representations with the given separator
205221
* string. The separator will not be appended to the beginning or the end.

0 commit comments

Comments
 (0)
Please sign in to comment.