chapter four

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

 

This chapter covers

  • Using log messages to understand an app’s behavior
  • Correctly implementing log capabilities in your app
  • Using AI assistants to investigate large log files
  • Avoiding problems caused by logs

This chapter discusses using log messages recorded by an app. The concept of logging didn’t appear with software. For centuries, people used logs to understand past events and processes better. In fact, 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 4.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 4.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 problem or discover breaches in the app.

4.1 Investigating issues with logs

4.1.1 Using logs to identify exceptions

4.1.2 Using exception stack traces to identify what calls a method

4.1.3 Measuring time spent to execute a given instruction

4.1.4 Investigating problems in multithreaded architectures

4.2 Implementing logging

4.2.1 Persisting logs

4.2.2 Defining logging levels and using logging frameworks

4.2.3 Problems caused by logging and how to avoid them

Summary