Software Design and Development :: CS 246

10 Prepare : Reading

Logging

Objectives

Introduction

Logging can provide a lot of benefits to your project. First, it allows you to use "Tracer Bullet Debugging" in order to see where things are going wrong in the code.

For example, imagine this code:

void doSomething(int start) {
    log("About to start doSomething() with start = " + start);
    
    doOtherThing();
    log("Finished doing other thing");

    while(...) {
    ...
    }

    log("Finished loop...");

}

If you execute that code, and your program crashes, you can now look at the logs and see exactly at one point the program failed. If you see the first and second log statements, but not the third, that means something went wrong inside the loop. This is called Tracer Bullet Debugging.

Another use for logging is to detect the conditions that exist when something goes wrong. This is especailly useful if a user reports a problem with your program that you can't reproduce. By looking at the user's logs, you might notice that whenever the doSomething() function is called with start set to -1, it causes a crash.

A final common use for logging is for security audits. Being able to see when a specific person accessed a particular resource.

Reading

Read the following resources:

  1. Read about the log class in Android.

  2. Read about the Android Studio logcat system.

  3. Review the this Stack Overflow post about log levels.

Reading Quiz

Don't forget to take the Reading Quiz in I-Learn. This quiz can be taken as many times as you like, but you must score at least 90% to pass. If you fail the quiz, review the relevant parts of the reading and try again.