Java library for styling stacktrace exceptions with html / css

I convert the body of my exception to a string and then send a message about this exception with the given address in java. I want to format my exception string using html to make it human-readable format, similar to how it is displayed when the stack overflows. I was wondering if there are any Java libraries that do this?

StringWriter stringWriter = new StringWriter();
PrintWriter printWriter = new PrintWriter(stringWriter);
t.printStackTrace(printWriter);
String body = stringWriter.toString();
//add html to body here
setMessageBody(body);

To reinforce, I mean things like a separate line with <br/>, display class name names with a different color font, display line numbers with a different color font. This can be done with some regular expressions, but I was wondering if there is a library that does this out of the box.

+3
source share
3 answers

Yes, there are a couple, and they even have a "free" e-mail server: use a Java framework, for example slf4j or the log4j .

All of these frameworks can create HTML letters with a small configuration. The general approach is as follows:

  • Create a registrar for all exceptions or one registrar for each class. The former is easier to set up, the latter gives you more freedom.
  • add to this registrar an application configured to send letters

If you do not want to use logging in your application, you can write your own application that reuses existing formats.

+1
source

, , HTML <pre>. , , .

<pre>
java.lang.ClassCastException: java.lang.Double cannot be cast to java.math.BigDecimal
        at org.hibernate.type.descriptor.java.BigDecimalTypeDescriptor.unwrap(BigDecimalTypeDescriptor.java:36)
        at org.hibernate.type.descriptor.sql.DecimalTypeDescriptor$1.doBind(DecimalTypeDescriptor.java:65)
        at org.hibernate.type.descriptor.sql.BasicBinder.bind(BasicBinder.java:90)
        at org.hibernate.type.AbstractStandardBasicType.nullSafeSet(AbstractStandardBasicType.java:286)
</pre>
+6

I wrote this, https://github.com/StefanLiebenberg/html-exception-formatter

Its a simple utility to format exceptions as readable html.

String html = new HtmlExceptionFormatter().toString(exception);
0
source

All Articles