Package 

Class Logger


  • 
    public class Logger
    
                        

    Utility class that simplifies the use of android.util.Log by improving the call to all log methods by supplying arguments as parameters instead of creating a string. This avoids useless memory allocations when not requested: the StringBuilder itself, the buffer and the String object. The new methods check in advance if the level is enabled and only after the string message with arguments is created.

    Note: This class has best usage with Log.

    Classical usage:

    if (BuildConfig.DEBUG) {
        Log.setLevel(Level.INFO);
    } else {
        Log.setLevel(Level.SUPPRESS);
    }
    Logger logger = new Logger("MyNewTag");
    

    Advanced usage:

    The {@code Logger} constructor will reset the {@code Log.customTag} to {@code null}! So at the next static call of {@code Log.v/d/i/w/e(...);} it will log the current filename as tag.
    public class MyClass {
        private Logger logger;
    
        public MyClass() {
            if (Log.customTag == null) Log.useTag("MyClass");
            this.logger = new Logger(Log.customTag);
            ...
        }
    
        public static void useTag(String tag) {
            Log.useTag(tag);
        }
    }
    
    // Usage
    MyClass.useTag("MyNewSmartTag");
    MyClass myClass = new MyClass();
    
    • Constructor Detail

    • Method Detail

      • v

         void v(String msg, Array<Object> args)

        Sends a VERBOSE log message.

        Parameters:
        msg - the message you would like logged
        args - the extra arguments for the message
      • d

         void d(String msg, Array<Object> args)

        Sends a DEBUG log message.

        Parameters:
        msg - the message you would like logged
        args - the extra arguments for the message
      • i

         void i(String msg, Array<Object> args)

        Sends an INFO log message.

        Parameters:
        msg - the message you would like logged
        args - the extra arguments for the message
      • w

         void w(String msg, Array<Object> args)

        Sends a WARN log message.

        Parameters:
        msg - the message you would like logged
        args - the extra arguments for the message
      • w

         void w(Throwable t, String msg, Array<Object> args)

        Sends a WARN log message with the Exception at the end of the message.

        Parameters:
        t - The exception to log
        msg - the message you would like logged
        args - the extra arguments for the message
      • e

         void e(String msg, Array<Object> args)

        Sends an ERROR log message.

        Parameters:
        msg - the message you would like logged
        args - the extra arguments for the message
      • e

         void e(Throwable t, String msg, Array<Object> args)

        Sends an ERROR log message with the Exception at the end of the message.

        Parameters:
        t - The exception to log
        msg - the message you would like logged
        args - the extra arguments for the message
      • wtf

         void wtf(String msg, Array<Object> args)

        What a Terrible Failure: Report a condition that should never happen.

        Parameters:
        msg - the message you would like logged
        args - the extra arguments for the message
      • wtf

         void wtf(Throwable t, String msg, Array<Object> args)

        What a Terrible Failure: Report a condition that should never happen with the Exceptionat the end of the message.

        Parameters:
        t - The exception to log
        msg - the message you would like logged
        args - the extra arguments for the message