orhanobut / logger is a handy library for viewing logs on Android. This section describes how to set the log level to display only error logs in the release version.
Prepare a class that implements LogAdapter. BuildConfig.DEBUG will be false in the release version, so here we will not show anything other than error level logs in the release version.
public class MyLogAdapter implements LogAdapter {
@Override
public void v(String tag, String message) {
if (BuildConfig.DEBUG) {
Log.v(tag, message);
}
}
@Override
public void d(String tag, String message) {
if (BuildConfig.DEBUG) {
Log.d(tag, message);
}
}
@Override
public void i(String tag, String message) {
if (BuildConfig.DEBUG) {
Log.i(tag, message);
}
}
@Override
public void w(String tag, String message) {
if (BuildConfig.DEBUG) {
Log.w(tag, message);
}
}
@Override
public void e(String tag, String message) {
Log.e(tag, message);
}
@Override
public void wtf(String tag, String message) {
if (BuildConfig.DEBUG) {
Log.wtf(tag, message);
}
}
}
In Application etc., initialize Logger and set MyLogAdapter.
public class MyApplication extends Application {
@Override
public void onCreate() {
super.onCreate();
Logger.init(getString(R.string.app_name)).logAdapter(new MyLogAdapter());
}
}
Logger.d("Displayed only debug build");
The following is an example of output when using Logger. Only the debug version is output.
I have a project that works on Logger @ github.
Recommended Posts