DDMS is good for debugging, but when you are ready to release the app, it just seems excessive that it would be sending all this signal to the user's computer when USB connected.
Is it possible to suppress output to ddms? If so, how?
DDMS is good for debugging, but when you are ready to release the app, it just seems excessive that it would be sending all this signal to the user's computer when USB connected.
Is it possible to suppress output to ddms? If so, how?
The following is what I do. It is probably not as elegant as what you are expecting but it works:
public static final boolean DEBUG_ON = true;
//Log something
if (!DEBUG_ON) Log.d("tag", "my log message");
Then, just change the value of DEBUG_ON when you release your app.
if you don't use proguard, you have to manage the log yourself and in the manifest file make dubuggable false
<application
android:name="MyApplication"
android:icon="@drawable/gift"
android:label="@string/app_name" android:debuggable="@bool/build_log">
Here my custom log class
public class Lol {
public static final boolean ENABLE_LOG = true & MyApplication.sDebug;
private static final boolean DEBUG = true & ENABLE_LOG;
private static final boolean VERBOSE = true & ENABLE_LOG;
private static final boolean TEMP = true & ENABLE_LOG;
private static final boolean WARNING = true & ENABLE_LOG;
private static final boolean INFO = true & ENABLE_LOG;
private static final boolean ERROR = true & ENABLE_LOG;
public static void obvious(String tag, String msg) {
if (DEBUG) {
msg = "*********************************\n" + msg
+ "\n*********************************";
Log.d(tag, msg);
}
}
public static void d(String tag, String msg) {
if (DEBUG)
Log.d(tag, msg);
}
public static void d(boolean bool, String tag, String msg) {
if (TEMP&bool)
Log.d(tag, msg);
}
public static void i(String tag, String msg) {
if (INFO)
Log.i(tag, msg);
}
public static void e(String tag, String msg) {
if (ERROR)
Log.e(tag, msg);
}
public static void e(boolean bool, String tag, String msg) {
if (TEMP&bool)
Log.e(tag, msg);
}
public static void v(String tag, String msg) {
if (VERBOSE)
Log.v(tag, msg);
}
public static void w(String tag, String msg) {
if (WARNING)
Log.w(tag, msg);
}
public static String getStackTraceString(Exception e) {
return Log.getStackTraceString(e);
}
public static void w(String tag, String msg, Exception e) {
if (WARNING)
Log.w(tag, msg,e);
}
}
Keep in mind that not everything you see in DDMS is even from your app. Behind the scenes DDMS is actually using adb
to run logcat
on the device to output the system log that all apps send logging info to. This information is only sent over usb when connected to adb and logcat is run. For most users this will normally not be output. While you should cleanup your debug output in your application to be minimal you don't need to worry about the other output.
ADT will now normally set the debuggable attribute correctly for you in your manifest, assuming you do not add it to the manifest at all. The manifest debuggable attribute controls if debugging tools (DDMS) are able to connect to your running process.
An alternate approach to using compile time flags to enable or disable debugging is to use the Log.isLoggable (String tag, int level)
api in combination with adb shell setprop
This is a little trickier though.