Over a million developers have joined DZone.

9 Strategies for a Faster Live Debug

DZone's Guide to

9 Strategies for a Faster Live Debug

Debugging a live app can be a pain. Here are nine strategies for faster debugging, including basic search strategies and more elegant techniques.

· Performance Zone
Free Resource

Debugging a live application can be a real pain, especially if you’re running a microservices architecture with elastic servers or, in the case of Cardinal Peak, software and hardware solutions for a variety of remote and custom devices. In this post, I describe approaches to extracting useful insights out of your Loggly account. Most examples are written standalone, but throughout I’ll reference “the bug we’re trying to find” as an incentive for you to look more deeply. So, here are nine strategies for faster debugging, including basic search strategies, as well as more elegant techniques that are possible if you log in JSON.

1. Put Your Focus on a Specific Time Slice

One of the most important factors of a log event is the time it occurred. Log events very rarely occur at the same recorded instant, so knowing the time tells you the statement. Perhaps even more importantly, the proximity in time between two log statements strongly predicts their relationship.

You can enter a DateTime-like value into the time fields or select from the calendar in Loggly search.

9 Strategies for Faster Live Debug 1

Substrings of a valid DateTime formatted string are accepted, like 2016-10-26 and 2016-10-26T08:00:00. Additionally, certain shorthand strings are available, such as %s, %m, %h, %d, and %w where % is an integer. They are not composable.

Here are some common scenarios:

9 Strategies for Faster Live Debug 2

“We know the event happened two days ago.”

Loggly search 20 minutes ago

“This bug just occurred on my machine,” or “I’m reproducing the bug now.”

If you’re working with a remote system, you can use {-1m, now} to watch real-time logs scroll by with some latency. You have to manually refresh the search every minute or so. Loggly also provides Live Tail, which gives you real-time response. Great technology!9 Strategies for Faster Live Debug 4

2. Search for Specific Known Strings

The string field is the most obvious way to search. Use it like a net and gain information on any other field quickly. If you know the device_id of a particular device you’re trying to debug, use basic string search to find the correct JSON pattern, then select from there. (See "Using JSON to Identify Patterns and Errors"below.) Or, you might search on a customer ID.

3. View Surrounding Events

Once you’ve found the log event you want, it is usually mixed up with all of the other similar events that satisfied your search. These events are not necessarily relevant. They are usually just copies of the same event you want from different instances. Click View Surrounding Events to see a small time slice directly around your target log event.

9 Strategies for Faster Live Debug 5

When you’re a beginner, Loggly seems to have failed. View Surrounding Events has now removed your filters and search results. Now add and modify your terms from the previous search to bring you the exact context you need for the target log statement. If you don’t do this, your target statement is nestled amidst potentially thousands of out-of-context logs and logs from other sources. Loggly has informed me that an upcoming, updated interface will correct this particular issue.

4. Identify Relationships

Once you’ve found the log event that declares the bug you’re working on, your search should lead you back in time toward the root cause of the event. If you’ve followed at least some of the strategies from my post on How to Write Effective Logs for Remote Logging, you use the techniques below to narrow your search. The correctly phrased search and time slice is the entire lifecycle of the bug you’re trying to fix.

Using JSON to Identify Patterns and Errors

The true power of Loggly emerges when you start recording all of your data in a JSON format. Real-time key-value indexing is a feature of certain noSQL databases, and it provides a tremendous amount of power, especially using MapReduce. Because you have used JSON to structure your log data, you now have insight into it—all of it.

When it comes to structured logs, Loggly Dynamic Field Explorer gives you the most power. From here, you can compose statements about any indexed field, constructing queries as powerful as precomputed views on the fly with a much simpler syntax.

9 Strategies for Faster Live Debug 6

5. Isolate a Specific Server or Device

Use Loggly Dynamic Field Explorer to pick the device you want from a list and to easily see usage information across devices. For example, you might have logged remoteAddr from Apache.

9 Strategies for Faster Live Debug 7

Clicking begins an index search, reducing your data only to those that satisfy the expression.

9 Strategies for Faster Live Debug 8

These filters can be combined as far as you care to. I have built searches with five or six expressions. Importantly, note that if you click the button that looks like this:9 Strategies for Faster Live Debug 9...from here, the number of log source options has been greatly reduced to reflect your own log universe. Loggly always updates Loggly Dynamic Field Explorer to reflect the current set of log results. Reducing your expressions this way is very easy. Remember that you have to clear all filters and search results before you can find more general data again. Or, save your search and press + New to start a fresh search on the global dataset.

6. Search a Specific Version Number

Now that we have only requests from, we can find a version number for it:

9 Strategies for Faster Live Debug 10

Unsurprisingly, the bug we want is in curl/7.35.0. If we knew the target platform was Mozilla/5.0…Trident/6.0, then we’d be done looking for that specific device and could broaden our search to all of its specific activity.

7. Find a Specific State

You can add as many fields as you want in this fashion. Loggly also shows the number of occurrences of each event. By paying attention to them you can more easily do “data forensics” where you are able to find very elusive bugs by casually looking through log data.

9 Strategies for Faster Live Debug 11

In the above, we see a quick way to target a 404 response to a GET request. Instead of narrowing our results search by search, now we can just peruse the 18 responses and pick the one we want. If you use the metadata approaches I describe in my previous post, you can easily get other relevant properties from that easy-to-find log message.

As you can see, there are many more ways to build data views using the Loggly Dynamic Field Explorer. You decide what the most salient information is and begin your searches there. Often one or two queries bring you exactly to your target.

8. Use Saved Searches to Get Your Team on the Same Page

An overlooked gem of Loggly is that a saved search is shared with all users of the account. This makes communicating about your results easy. Instead of describing what you’ve done, share it. You can also share a permalink for any search. Or, with the JIRA integration available to Enterprise customers, you can automatically incorporate log events into a new JIRA ticket.

9. Monitor Errors (But Don’t Obsess Over Them)

Loggly also helps with keeping your logs and codebase clean. It is easy to set up an error monitor with a saved search. Each time you view your Dashboard you can see if any unreported, lingering errors occur.

This is also a place of terrible rabbit-holing, so use your time wisely. Determine first if you can easily solve an error that appears in a saved search. If not, it is usually better to report the error and resolve it through a normal work cycle. Investigate if the error has been reported by others, who reported it, and how frequently it occurs. Teach your managers to use Loggly Dynamic Field Explorer to triage issues on their own. Use your judgment, but given a little bit of time, you can expect to have clean error monitoring. At this point error monitoring lets you fix issues before they’re even reported.

performance ,debugging ,live applications

Published at DZone with permission of Thomson Comer, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

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

{{ parent.tldr }}

{{ parent.urlSource.name }}