chapter five

5 How to read log files

 

This chapter covers

  • How to read stack traces effectively
  • Why the command line is a log file’s best friend
  • Tools to read log files efficiently

Previously, we learned how to create log files using System.Logger and briefly mentioned stack traces. Now it’s time to explore the other side of logging: reading and interpreting what we’ve written.

Imagine if you opened the logs of a production system with Notepad. These files could easily grow to hundreds of megabytes, sometimes even gigabytes. Notepad loads the whole file into memory, which will likely fail. Even if it worked, you’d have to scroll through thousands of lines before finding a trace of the problem. If you find it, it comes in the form of a stack trace. Stack traces are chains of method calls that led to an exception. They are generated from Java and often printed into a log file.

If you want to look for these stack traces in big files, you need more powerful tools. Most of them are command-line tools that can help you navigate to the right place. Before we look at these tools, let’s start with the one thing every developer must be able to read: the stack trace in a log.

5.1 Reading the bubbles: stack traces

In the last chapter, we learned that exceptions interrupt the normal flow of a program. They are thrown from one method to another, and when we see them in our log file, we call them stack traces.

5.1.1 A real life stack trace

5.1.2 Breaking down stack traces

5.1.3 Context matters: finding the why

5.1.4 Interpreting "Caused by"

5.1.5 Suppressed exceptions

5.1.6 More tips for reading stack traces

5.2 Command line: Opening the black box

5.2.1 Navigating on the command line

5.2.2 Reading logs efficiently

5.2.3 Just read the latest with tail

5.2.4 Advanced searching with grep

5.3 Summary