5 Making the most of logs: Auditing an app’s behavior

 

This chapter covers

  • Effectively using logs to understand an app’s behavior
  • Correctly implementing log capabilities in your app
  • Avoiding issues caused by logs

In this chapter, we will discuss using log messages that an app records. The concept of logging didn’t first appear with software. For centuries, people used logs to help them understand past events and processes. People have used logging since writing was invented, and we still use it today. All ships have logbooks. Sailors record decisions (direction, speed increase or decrease, etc.) and given or received orders, along with any encountered event (figure 5.1). If something happens to the onboard equipment, they can use the logbook notes to understand where they are and navigate to the nearest shore. If an accident happens, the logbook notes can be used in the investigation to determine how the unfortunate event could have been avoided.

Figure 5.1 Sailors store events in logs that they can use to determine their route or analyze the crew’s response to a given event. In the same way, apps store log messages so that developers can later analyze a potential issue or discover breaches in the app.

If you’ve ever watched a chess game, you know that both players write down each piece’s movement. Why? These logs help them re-create the entire game afterward. They study both their and their opponent’s moves to spot potential mistakes or vulnerabilities.

5.1 Investigating issues with logs

5.1.1 Using logs to identify exceptions

5.1.2 Using exception stack traces to identify what calls a method

5.1.3 Measuring time spent to execute a given instruction

5.1.4 Investigating issues in multithreaded architectures

5.2 Implementing logging

5.2.1 Persisting logs

5.2.2 Defining logging levels and using logging frameworks

5.2.3 Problems caused by logging and how to avoid them

5.3 Logs vs. remote debugging

Summary