From bdbd5bc1ee5c3219406ae684a6f0197c42928c6d Mon Sep 17 00:00:00 2001 From: Eric House Date: Wed, 9 Jan 2019 19:41:33 -0800 Subject: [PATCH] disable logging for tagged release builds --- xwords4/android/app/build.gradle | 5 +++ .../java/org/eehouse/android/xw4/Log.java | 33 +++++++++++++------ 2 files changed, 28 insertions(+), 10 deletions(-) diff --git a/xwords4/android/app/build.gradle b/xwords4/android/app/build.gradle index 91b797cd4..18ec13082 100644 --- a/xwords4/android/app/build.gradle +++ b/xwords4/android/app/build.gradle @@ -16,6 +16,10 @@ if (! forFDroid) { } GITREV = GITREV.execute().text.trim() +// Make CURTAG non-empty IFF we're at a tag (release build) +def CURTAG = "git describe --exact-match".execute().text.trim() +// print "CURTAG: " + CURTAG + "\n" + apply plugin: 'com.android.application' @@ -63,6 +67,7 @@ android { productFlavors { all { buildConfigField "String", "BUILD_INFO_NAME", "\"${BUILD_INFO_NAME}\"" + buildConfigField "boolean", "IS_TAGGED_BUILD", "${CURTAG}" == '' ? "false" : "true" resValue "string", "invite_prefix", "/and/" } diff --git a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/Log.java b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/Log.java index c54fce834..02ac43220 100644 --- a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/Log.java +++ b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/Log.java @@ -24,27 +24,40 @@ import java.util.Formatter; public class Log { private static final String PRE_TAG = BuildConfig.FLAVOR + "-"; + private static final boolean LOGGING_ENABLED + = BuildConfig.DEBUG || !BuildConfig.IS_TAGGED_BUILD; + private static final boolean ERROR_LOGGING_ENABLED = true; public static void d( String tag, String fmt, Object... args ) { - String str = new Formatter().format( fmt, args ).toString(); - android.util.Log.d( PRE_TAG + tag, str ); + if ( LOGGING_ENABLED ) { + String str = new Formatter().format( fmt, args ).toString(); + android.util.Log.d( PRE_TAG + tag, str ); + } } public static void w( String tag, String fmt, Object... args ) { - String str = new Formatter().format( fmt, args ).toString(); - android.util.Log.w( PRE_TAG + tag, str ); + if ( LOGGING_ENABLED ) { + String str = new Formatter().format( fmt, args ).toString(); + android.util.Log.w( PRE_TAG + tag, str ); + } } public static void e( String tag, String fmt, Object... args ) { - String str = new Formatter().format( fmt, args ).toString(); - android.util.Log.e( PRE_TAG + tag, str ); + if ( ERROR_LOGGING_ENABLED ) { + String str = new Formatter().format( fmt, args ).toString(); + android.util.Log.e( PRE_TAG + tag, str ); + } } public static void i( String tag, String fmt, Object... args ) { - String str = new Formatter().format( fmt, args ).toString(); - android.util.Log.i( PRE_TAG + tag, str ); + if ( LOGGING_ENABLED ) { + String str = new Formatter().format( fmt, args ).toString(); + android.util.Log.i( PRE_TAG + tag, str ); + } } public static void ex( String tag, Exception exception ) { - w( tag, "Exception: %s", exception.toString() ); - DbgUtils.printStack( tag, exception.getStackTrace() ); + if ( LOGGING_ENABLED ) { + w( tag, "Exception: %s", exception.toString() ); + DbgUtils.printStack( tag, exception.getStackTrace() ); + } } }