For the More Curious: Log Levels

When you use the android.util.Log class to send log messages, you control not only the content of a message but also a level that specifies how important the message is. Android supports five log levels, shown in Table 3.2. Each level has a corresponding function in the Log class. Sending output to the log is as simple as calling the corresponding Log function.

Table 3.2  Log levels and functions

Log level Function Used for

ERROR

Log.e(…)

errors

WARNING

Log.w(…)

warnings

INFO

Log.i(…)

informational messages

DEBUG

Log.d(…)

debug output (may be filtered out)

VERBOSE

Log.v(…)

development only

In addition, each of the logging functions has two signatures: one that takes a TAG string and a message string, and a second that takes those two arguments plus an instance of Throwable, which makes it easy to log information about a particular exception that your application might throw. Listing 3.5 shows some sample log function signatures.

Listing 3.5  Different ways of logging in Android

// Log a message at DEBUG log level
Log.d(TAG, "Current question index: $currentIndex")

try {
    val question = questionBank[currentIndex]
} catch (ex: ArrayIndexOutOfBoundsException) {
    // Log a message at ERROR log level, along with an exception stack trace
    Log.e(TAG, "Index was out of bounds", ex)
}
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.222.111.24