back to all blogsSee all blog posts

Separate stack trace from messages in logged exceptions in Open Liberty 22.0.0.8-beta

image of author
Ryan Storey on Jul 7, 2022

Open Liberty 22.0.0.8-beta separates stack trace from logged messages by offering new fields for Open Liberty JSON logging and for the Logstash Collector feature. This enables easier-to-read visualizations in downstream log analysis tools.

The Open Liberty 22.0.0.8-beta includes the following beta features (along with all GA features):

Stack trace separated from logged messages in logging records

The stack trace is now separated from logged messages in logging records so that log analysis tools can present them more clearly. This makes visualizations of the logs by downstream log analysis tools easier to read when you are identifying any issues encountered by the application. Previously, any logging record originating from a Java Logger object that made use of any of the methods that accept a Throwable parameter would simply append the stack trace to the existing message field. Keeping the message field solely for the logged message and having a separate field for the stack trace and exception type enhances the effectiveness of log analysis tools down stream.

Java’s Logging API provides methods that allow you to include a Throwable as a parameter. When the Throwable object is used, Open Liberty’s JSON logging provides two new fields, ibm_stackTrace and ibm_exceptionName, and the Open Liberty Logstash Collector feature provides two new fields, stackTrace and exceptionName. The stack trace fields present only the stack trace of the Throwable object. The exception name fields present the type of exception of the Throwable object.

Example:

For the example we will only be showing the message log record for Open Liberty’s JSON logging.

Application with the following code snippet:

Logger logger = Logger.getLogger(MyResource.class.getCanonicalName());
Exception exception = new IllegalArgumentException("ouch");
logger.log(Level.INFO, "exception message", exception);

Previous Open Liberty JSON logging output:

{
    "type": "liberty_message",
    ...
    "message": exception message  java.lang.RuntimeException: ouch\r\n\tatmy.package.MyResource.get(MyResource.java:32)\r\n\tatmy.package.MyResource.get(MyResource.java:20)\r\n...",
    ...
}

New Open Liberty JSON logging output:

{
    "type": "liberty_message",
    ...
    "message": exception message",
    "ibm_exceptionName":"java.lang.IllegalArgumentException",
    "ibm_stackTrace":"java.lang.IllegalArgumentException: ouch\r\n\tat my.package.MyResource.get(MyResource.java:20)\r\n...",
    ...
}

Try it now

To try out these features, just update your build tools to pull the Open Liberty All Beta Features package instead of the main release. The beta works with Java SE 18, Java SE 17, Java SE 11, and Java SE 8.

If you’re using Maven, here are the coordinates:

<dependency>
  <groupId>io.openliberty.beta</groupId>
  <artifactId>openliberty-runtime</artifactId>
  <version>22.0.0.8-beta</version>
  <type>pom</type>
</dependency>

Or for Gradle:

dependencies {
    libertyRuntime group: 'io.openliberty.beta', name: 'openliberty-runtime', version: '[22.0.0.8-beta,)'
}

Or take a look at our Downloads page.

Your feedback is welcomed

Let us know what you think on our mailing list. If you hit a problem, post a question on StackOverflow. If you hit a bug, please raise an issue.

Tags