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.
This commit is contained in:
parent
ad41bacb48
commit
a5b6c6cc2d
1 changed files with 30 additions and 9 deletions
|
@ -10,28 +10,49 @@ public final class Ln {
|
||||||
|
|
||||||
private static final String TAG = "scrcpy";
|
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() {
|
private Ln() {
|
||||||
// not instantiable
|
// not instantiable
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static boolean isEnabled(Level level) {
|
||||||
|
return level.ordinal() >= THRESHOLD.ordinal();
|
||||||
|
}
|
||||||
|
|
||||||
public static void d(String message) {
|
public static void d(String message) {
|
||||||
Log.d(TAG, message);
|
if (isEnabled(Level.DEBUG)) {
|
||||||
System.out.println("DEBUG: " + message);
|
Log.d(TAG, message);
|
||||||
|
System.out.println("DEBUG: " + message);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void i(String message) {
|
public static void i(String message) {
|
||||||
Log.i(TAG, message);
|
if (isEnabled(Level.INFO)) {
|
||||||
System.out.println("INFO: " + message);
|
Log.i(TAG, message);
|
||||||
|
System.out.println("INFO: " + message);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void w(String message) {
|
public static void w(String message) {
|
||||||
Log.w(TAG, message);
|
if (isEnabled(Level.WARN)) {
|
||||||
System.out.println("WARN: " + message);
|
Log.w(TAG, message);
|
||||||
|
System.out.println("WARN: " + message);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void e(String message, Throwable throwable) {
|
public static void e(String message, Throwable throwable) {
|
||||||
Log.e(TAG, message, throwable);
|
if (isEnabled(Level.ERROR)) {
|
||||||
System.out.println("ERROR: " + message);
|
Log.e(TAG, message, throwable);
|
||||||
throwable.printStackTrace();
|
System.out.println("ERROR: " + message);
|
||||||
|
throwable.printStackTrace();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue