Android Open Source - template-android Log






From Project

Back to project page template-android.

License

The source code is released under:

MIT License

If you think the Android project template-android listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.org.application.util;
/* w ww  . j av a2s  .co  m*/
import dagger.Module;

/**
 *  Mimics the android.util.Log class to add the ability to ignore logs during release.
 *  Will have gradle hooked up to this at a later time.
 */
@SuppressWarnings({"WeakerAccess", "UnusedDeclaration"})
@Module
public class Log{
    private static final String TAG = Log.class.getSimpleName();


    public static final int ASSERT = android.util.Log.ASSERT;
    public static final int DEBUG = android.util.Log.DEBUG;
    public static final int ERROR = android.util.Log.ERROR;
    public static final int INFO = android.util.Log.INFO;
    public static final int VERBOSE = android.util.Log.VERBOSE;
    public static final int WARN = android.util.Log.WARN;

    public static boolean sLogEnabled = false;
    public static int sLogLevel = ERROR;

    public static int   d(String tag, String msg){
        if(sLogEnabled && DEBUG >= sLogLevel)
            return android.util.Log.d(tag, msg);
        else
            return 0;
    }

    public static int   d(String tag, String msg, Throwable tr){
        if(sLogEnabled && DEBUG >= sLogLevel)
            return android.util.Log.d(tag, msg, tr);
        else
            return 0;
    }
    public static int   e(String tag, String msg){
        if(sLogEnabled && ERROR >= sLogLevel)
            return android.util.Log.e(tag, msg);
        else
            return 0;
    }
    public static int   e(String tag, String msg, Throwable tr){
        if(sLogEnabled && ERROR >= sLogLevel)
            return android.util.Log.e(tag, msg, tr);
        else
            return 0;
    }

    public static String   getStackTraceString(Throwable tr){
        return android.util.Log.getStackTraceString(tr);
    }

    public static int   i(String tag, String msg){

        if(sLogEnabled && INFO >= sLogLevel)
            return android.util.Log.i(tag, msg);
        else
            return 0;
    }
    public static int   i(String tag, String msg, Throwable tr){
        if(sLogEnabled && INFO >= sLogLevel)
            return android.util.Log.i(tag, msg, tr);
        else
            return 0;
    }

    public static boolean   isLoggable(String tag, int level){
        return android.util.Log.isLoggable(tag, level);
    }
    public static int   println(int priority, String tag, String msg){
        return android.util.Log.println(priority, tag, msg);
    }
    public static int   v(String tag, String msg){
        if(sLogEnabled && VERBOSE >= sLogLevel)
            return android.util.Log.v(tag, msg);
        else
            return 0;
    }
    public static int   v(String tag, String msg, Throwable tr){
        if(sLogEnabled && VERBOSE >= sLogLevel)
            return android.util.Log.v(tag, msg, tr);
        else
            return 0;
    }
    public static int   w(String tag, Throwable tr){
        if(sLogEnabled && WARN >= sLogLevel)
            return android.util.Log.w(tag, tr);
        else
            return 0;
    }
    public static int   w(String tag, String msg, Throwable tr){
        if(sLogEnabled && WARN >= sLogLevel)
            return android.util.Log.w(tag, msg, tr);
        else
            return 0;
    }
    public static int   w(String tag, String msg){
        if(sLogEnabled && WARN >= sLogLevel)
            return android.util.Log.w(tag, msg);
        else
            return 0;
    }
    public static int   wtf(String tag, Throwable tr){
        if(sLogEnabled && ASSERT >= sLogLevel)
            return android.util.Log.wtf(tag, tr);
        else
            return 0;
    }
    public static int   wtf(String tag, String msg){
        if(sLogEnabled && ASSERT >= sLogLevel)
            return android.util.Log.wtf(tag, msg);
        else
            return 0;
    }
    public static int   wtf(String tag, String msg, Throwable tr){
        if(sLogEnabled && ASSERT >= sLogLevel)
            return android.util.Log.wtf(tag, msg, tr);
        else
            return 0;
    }

}




Java Source Code List

com.org.application.App.java
com.org.application.Modules.java
com.org.application.Modules.java
com.org.application.Modules.java
com.org.application.mock.Foo.java
com.org.application.mock.IFoo.java
com.org.application.mock.MockFoo.java
com.org.application.module.MockFooModule.java
com.org.application.module.ReleaseModule.java
com.org.application.ui.activity.MainActivity.java
com.org.application.util.Log.java