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

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 about your log4j event logs.

By running 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 you java code, which in turn will help you create better quality code.

Try Xpolog Now

Preliminary

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 where I showed you how to define 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.

Quality of code - parsing class and priority

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:

quality of code3

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:

priority error in log errors count group by class order by count desc

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 automatically 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:

priority error AND class xpologeyedatafiltersQueryFilter IN log errors

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

Although perfect code is seldom found, our quest for exceptionally high quality code has now been given a very powerful boost.

Try Xpolog Now

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 “Getting the Maximum from your log4j logs”.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s