One Small Error in Java Code, One Giant Leap for Java Code Quality

DZone 's Guide to

One Small Error in Java Code, One Giant Leap for Java Code Quality

A tutorial on how to use the free XpoLog software to find errors in your Java code.

· Java Zone ·
Free Resource

In this series of posts I am covering some of the many ways you can benefit from XpoLog and especially on how to get the most valuable information from your log4j event logs.

By running the XpoLog Analytic Search on your log4j data, you can among other things measure your application performance and thread activity, measure code activity with class and method analytics on log4j, build security analysis, and make use of various visualization gadgets for maximum analysis.

In this post I will show you how XpoLog can help you find errors in your Java code, which in turn will help you create better quality code. If you want to follow as you read along, you can download our software for free here.


We are using the same java application as in my previous post, With Great Availability Comes Great Performance, the one that runs various types of processes and uses log4j to log its activities. One of these logs is called errors, and it notes all the errors found in each of the classes of the code.

We will now see the benefits of the parsing process we did earlier. Quick re-cap:

In my post that spoke about defining log4j Patterns in SysLog, I showed you that XpoLog has an advanced built-in mechanism to detect the structure, or pattern, of the incoming log. But as a user, you can edit and fine-tune these patterns to suit your needs.

You can create a detailed conversion pattern while adding your log4j log in XpoLog Center, setting the pattern to reflect the layout you defined in the log4j configuration. For the sake of our use case, we made sure to parse our log error to include separate columns for the Priority (ERROR, in our case) and the Class.

Image title

Investigating the Quality of the Code

We now want to check which classes in the code of our application wrote the most errors. By locating these errors quickly, we can create high quality code significantly faster. We do this by looking into the log error.

For a general view, we want to see the number of errors over a time span of 4 hours, just to make sure there are not too many.

In XpoLog Center, on the Search page, in the search field, type:

priority = error in log.errors | count | interval 1 hour

Since the log may also include anomalies that are fatal, we specifically search for the anomalies that are “just” errors.

We get the following result:

Image title

We see the errors are spread fairly evenly during this time and do not jump (spike) during specific times.

We now want to see which classes are responsible for the majority of the errors.

In XpoLog Center, on the Search page, in the search field, type:

priority = error in log.errors | count | group by class | order by count desc 

We get the following result:

Image title

We see that the class with the highest number of errors is xpolog.eye.data.filters.QueryFilter.

We would like to have a closer look at this class, and XpoLog gives you a very easy way to drill down into this particular class (or any other class on the list for that matter). All you need to do is click on the link (in the table) to xpolog.eye.data.filters.QueryFilter.

Once you click on the class, XpoLog will change the search-query in the Search field by adding this class to the query with the action Add to search (AND). The search field will now read as follows:

(priority=error) AND class=xpolog.eye.data.filters.QueryFilter IN log.errors  

We get the following (drill down) result:

Image title

We can now investigate the actual errors specifically found in the class xpolog.eye.data.filters.QueryFilter.

Perfect code is seldom found, but our quest for exceptionally high quality code has certainly been given a powerful boost.

In my next post I will show you how to view all of what we have found in XpoLog Apps. I will show you how to create Apps, Dashboards and Gadgets to better visualize all your data. Stay tuned for my next post or go directly to our hands-on guide “Getting the Maximum from your log4j logs”.


Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}