Created
October 15, 2013 12:12
-
-
Save SebastianEngel/6990630 to your computer and use it in GitHub Desktop.
Wrapper class for Timber logging offering static method calls, e.g. TimberLogger.d("Hello %s", user.name). Evaluates BuildConfig.DEBUG to decide if an instance of Timber.DEBUG or Timber.PROD will be used.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package de.bsr.android.util; | |
import com.example.app.BuildConfig; | |
import timber.log.Timber; | |
/** | |
* Wrapper class for Timber that evaluates <code>BuildConfig.DEBUG</code> on construction | |
* and uses Timber.DEBUG or Timber.PROD appropriately. In PROD mode, no logging is done at all. | |
* | |
* @author Sebastian Engel <[email protected]> | |
*/ | |
public class TimberLogger { | |
private static Logger instance; | |
private Timber timber; | |
private TimberLogger() { | |
timber = BuildConfig.DEBUG ? Timber.DEBUG : Timber.PROD; | |
} | |
private static TimberLogger getInstance() { | |
if (instance == null) { | |
instance = new TimberLogger(); | |
} | |
return instance; | |
} | |
public static void d(String s, Object... objects) { | |
getInstance().timber.d(s, objects); | |
} | |
public static void d(Throwable throwable, String s, Object... objects) { | |
getInstance().timber.d(throwable, s, objects); | |
} | |
public static void i(String s, Object... objects) { | |
getInstance().timber.i(s, objects); | |
} | |
public static void i(Throwable throwable, String s, Object... objects) { | |
getInstance().timber.i(throwable, s, objects); | |
} | |
public static void w(String s, Object... objects) { | |
getInstance().timber.w(s, objects); | |
} | |
public static void w(Throwable throwable, String s, Object... objects) { | |
getInstance().timber.w(throwable, s, objects); | |
} | |
public static void e(String s, Object... objects) { | |
getInstance().timber.e(s, objects); | |
} | |
public static void e(Throwable throwable, String s, Object... objects) { | |
getInstance().timber.e(throwable, s, objects); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment