Productivity, Technical

Debugging Adventures: How I Learned to Solve Problems Faster with Logs and a Debugger

Our developers face issues and find ways to solve them daily. Most of the problems can be seen and solved locally before any code is delivered to production, through tests and debugging. But sometimes, unexpected issues arise during the process of deploying code to production, or even worse, while customers are using our product.

In this story, I will tell you how I deal with bugs and issues, using a combination of debuggers. Plus, I’ll provide tips and best practices to help you get better at debugging with debuggers and logs.

Normal work day…

It was a regular work day before the end of the year and most of my team was absent for their own year-end plans. At first, I thought it would be a dull day, since we had already finished our tasks and deployed our code to production.

As usual, after making a cup of tea, I opened my laptop and checked our application, logs, monitor, and metrics to ensure everything was still under control. Suddenly, something bad happened.

Until it messed up by bug

Our front-end web isn’t working anymore; all requests return errors. Upon inspection of the network, most of the errors are 500 HTTP requests, which indicates an unhandled issue on the backend. This is not as expected and unluckily, our boss will have a presentation about our application that afternoon – which mean we have to fix the error before the end of lunch time.

The situation is urgent enough that I thought if the issue was not yet fixed before the demonstration, we would have to try another path by using mocked data (but luckily we don’t have to).

Finding a way to fix the issue

When a production problem arises, my first action is to open the application logs and review the error logs. This can provide valuable information and help me pinpoint which part of the application is having issues.

With the help of log query provided by Azure, we quickly detect the problem that come from the data returned from REST API we call internal not correctly handle and lead to NullPointerException. Now is just to point out where the data get wrong and fix it.

I opened my IDE, ran the debugger, and sent the request that returned a 500 status error. Using the debugging tool provided by IntelliJ, I was able to quickly identify the unhandled case. It turned out that the problem did not come from a missing case, but rather the data from the 3rd party REST API suddenly changed without any notice, making it difficult for us to adapt.

In the end, we were able to adapt to the changes and deliver new code just in time for the demonstration event and everyone was happy!

Lessons from the story

From a scary story above, here are some lessons that I can share to you for better at debugging and fixing issues:

  • Logs, logs and logs: Logs are crucially important for any application as they provide quick and valuable information that can be trusted.
  • Using debugger tool: Utilizing tools like the IntelliJ debugger can help identify and fix problems rapidly.
  • Given the importance of logs: it is crucial that they are written in a clear and simple manner.
  • Know which log level to use: To improve your logging, it’s important to know which log level to use. Log levels can help you separate the logs you want to see and prevent overwhelm from too many logs. Below are some log levels that are commonly used:
    • INFO: Used for inform about application status such as: start up, configuration state, event occurs…
    • WARNING: Display information about exceptions and cases that were handle by application.
    • ERROR: Indicate that the error or failed has occurred unexpectedly. Normally these logs are important and only appear when your application has something when wrong.
    • DEBUG: These messages provide technical information like database transactions, returned JSON data… . Typically used during the development and testing process.

Thank you for reading this article. Remember that debugging is a crucial part of software development, and it’s important to use all the available tools and resources to fix issues quickly and efficiently. Always keep in mind the lessons learned from this story and apply them to your own work. Happy debugging!