From a5b6c6cc2de9db8bb9b26e8eea82d44a60a2c774 Mon Sep 17 00:00:00 2001 From: Romain Vimont Date: Mon, 12 Feb 2018 17:19:52 +0100 Subject: [PATCH] Enable debug logs only for debug builds on server Print the logs only if their level is not under the threshold, which is defined to INFO in release mode and DEBUG in debug mode. --- .../main/java/com/genymobile/scrcpy/Ln.java | 39 ++++++++++++++----- 1 file changed, 30 insertions(+), 9 deletions(-) diff --git a/server/src/main/java/com/genymobile/scrcpy/Ln.java b/server/src/main/java/com/genymobile/scrcpy/Ln.java index 38269835..9364519e 100644 --- a/server/src/main/java/com/genymobile/scrcpy/Ln.java +++ b/server/src/main/java/com/genymobile/scrcpy/Ln.java @@ -10,28 +10,49 @@ public final class Ln { private static final String TAG = "scrcpy"; + enum Level { + DEBUG, + INFO, + WARN, + ERROR; + } + + private static final Level THRESHOLD = BuildConfig.DEBUG ? Level.DEBUG : Level.INFO; + private Ln() { // not instantiable } + public static boolean isEnabled(Level level) { + return level.ordinal() >= THRESHOLD.ordinal(); + } + public static void d(String message) { - Log.d(TAG, message); - System.out.println("DEBUG: " + message); + if (isEnabled(Level.DEBUG)) { + Log.d(TAG, message); + System.out.println("DEBUG: " + message); + } } public static void i(String message) { - Log.i(TAG, message); - System.out.println("INFO: " + message); + if (isEnabled(Level.INFO)) { + Log.i(TAG, message); + System.out.println("INFO: " + message); + } } public static void w(String message) { - Log.w(TAG, message); - System.out.println("WARN: " + message); + if (isEnabled(Level.WARN)) { + Log.w(TAG, message); + System.out.println("WARN: " + message); + } } public static void e(String message, Throwable throwable) { - Log.e(TAG, message, throwable); - System.out.println("ERROR: " + message); - throwable.printStackTrace(); + if (isEnabled(Level.ERROR)) { + Log.e(TAG, message, throwable); + System.out.println("ERROR: " + message); + throwable.printStackTrace(); + } } }