The Android SDK includes a useful logging utility class called android.util.Log. Logging messages are categorized by severity, with errors being the most severe, then warnings, informational messages, debug messages and verbose messages being the least severe. Each type of logging message has its own method. Simply call the method and a log message is created. The message types, and their related method calls are:

 
 

  • The Log.e() method is used to log errors.
  • The Log.w() method is used to log warnings.
  • The Log.i() method is used to log informational messages.
  • The Log.d() method is used to log debug messages.
  • The Log.v() method is used to log verbose messages.
  • The Log.wtf() method is used to log terrible failures that should never happen.

     
     

    Syntax

    Log.i(TAG, ”Informational message!”);  

     
     

    The first parameter of each Log method is a string called a tag. Common practice is to define a global static string to represent the overall application or the specific activity within the application such that log filters can be created to limit the log output to specific data. For example, you could define a string called TAG, as follows:

    private static final String TAG = ”MyTAG”;  

     
     

    Now anytime you use a Log method, you supply this tag. An informational logging message might look like this:

     
     

    You can also pass a Throwable object, usually on Exception, that will allow the Log to print a stack trace or other useful information.

     

    • try {  
    • // …  
    • catch (Exception exception) {  
    •     Log.e(TAG, ”An Exception Encountered. Application Exits.”, exception);  
    • }  

     

     
     

Incoming search terms:

  • ios throwable object

Tagged with:

Filed under: Uncategorized

Like this post? Subscribe to my RSS feed and get loads more!