rpicms-android

Android app for the RPICMS.
git clone git://archive.git.mtrnord.blog/RpicmsTeam/rpicms-android.git
Log | Files | Refs

LogWrapper.java (2194B)


      1 package de.nordgedanken.rpicms.common.logger;
      2 
      3 /**
      4  * Created by frank on 14.10.14.
      5  */
      6 import android.util.Log;
      7 
      8 /**
      9  * Helper class which wraps Android's native Log utility in the Logger interface.  This way
     10  * normal DDMS output can be one of the many targets receiving and outputting logs simultaneously.
     11  */
     12 public class LogWrapper implements LogNode {
     13 
     14     // For piping:  The next node to receive Log data after this one has done its work.
     15     private LogNode mNext;
     16 
     17     /**
     18      * Returns the next LogNode in the linked list.
     19      */
     20     public LogNode getNext() {
     21         return mNext;
     22     }
     23 
     24     /**
     25      * Sets the LogNode data will be sent to..
     26      */
     27     public void setNext(LogNode node) {
     28         mNext = node;
     29     }
     30 
     31     /**
     32      * Prints data out to the console using Android's native log mechanism.
     33      * @param priority Log level of the data being logged.  Verbose, Error, etc.
     34      * @param tag Tag for for the log data.  Can be used to organize log statements.
     35      * @param msg The actual message to be logged. The actual message to be logged.
     36      * @param tr If an exception was thrown, this can be sent along for the logging facilities
     37      *           to extract and print useful information.
     38      */
     39     @Override
     40     public void println(int priority, String tag, String msg, Throwable tr) {
     41         // There actually are log methods that don't take a msg parameter.  For now,
     42         // if that's the case, just convert null to the empty string and move on.
     43         String useMsg = msg;
     44         if (useMsg == null) {
     45             useMsg = "";
     46         }
     47 
     48         // If an exeption was provided, convert that exception to a usable string and attach
     49         // it to the end of the msg method.
     50         if (tr != null) {
     51             msg += "\n" + Log.getStackTraceString(tr);
     52         }
     53 
     54         // This is functionally identical to Log.x(tag, useMsg);
     55         // For instance, if priority were Log.VERBOSE, this would be the same as Log.v(tag, useMsg)
     56         Log.println(priority, tag, useMsg);
     57 
     58         // If this isn't the last node in the chain, move things along.
     59         if (mNext != null) {
     60             mNext.println(priority, tag, msg, tr);
     61         }
     62     }
     63 }
     64