diff --git a/app/src/server.c b/app/src/server.c index fa9230e075..7cfbef0d6c 100644 --- a/app/src/server.c +++ b/app/src/server.c @@ -259,6 +259,11 @@ execute_server(struct server *server, const struct server_params *params) { "/", // unused "com.genymobile.scrcpy.Server", SCRCPY_VERSION, +#ifndef NDEBUG + "debug", +#else + "info", +#endif max_size_string, bit_rate_string, max_fps_string, diff --git a/server/src/main/java/com/genymobile/scrcpy/Ln.java b/server/src/main/java/com/genymobile/scrcpy/Ln.java index 26f13a56ba..8112bb1cfa 100644 --- a/server/src/main/java/com/genymobile/scrcpy/Ln.java +++ b/server/src/main/java/com/genymobile/scrcpy/Ln.java @@ -15,12 +15,23 @@ enum Level { DEBUG, INFO, WARN, ERROR } - private static final Level THRESHOLD = BuildConfig.DEBUG ? Level.DEBUG : Level.INFO; + private static Level THRESHOLD; private Ln() { // not instantiable } + /** + * Initialize the log level. + *
+ * Must be called before starting any new thread. + * + * @param level the log level + */ + public static void initLogLevel(Level level) { + THRESHOLD = level; + } + public static boolean isEnabled(Level level) { return level.ordinal() >= THRESHOLD.ordinal(); } diff --git a/server/src/main/java/com/genymobile/scrcpy/Options.java b/server/src/main/java/com/genymobile/scrcpy/Options.java index d2cd9a15d5..06312a37a5 100644 --- a/server/src/main/java/com/genymobile/scrcpy/Options.java +++ b/server/src/main/java/com/genymobile/scrcpy/Options.java @@ -3,6 +3,7 @@ import android.graphics.Rect; public class Options { + private Ln.Level logLevel; private int maxSize; private int bitRate; private int maxFps; @@ -16,6 +17,14 @@ public class Options { private boolean stayAwake; private String codecOptions; + public Ln.Level getLogLevel() { + return logLevel; + } + + public void setLogLevel(Ln.Level logLevel) { + this.logLevel = logLevel; + } + public int getMaxSize() { return maxSize; } diff --git a/server/src/main/java/com/genymobile/scrcpy/Server.java b/server/src/main/java/com/genymobile/scrcpy/Server.java index 4ada08e686..54292868cf 100644 --- a/server/src/main/java/com/genymobile/scrcpy/Server.java +++ b/server/src/main/java/com/genymobile/scrcpy/Server.java @@ -119,48 +119,51 @@ private static Options createOptions(String... args) { "The server version (" + BuildConfig.VERSION_NAME + ") does not match the client " + "(" + clientVersion + ")"); } - final int expectedParameters = 13; + final int expectedParameters = 14; if (args.length != expectedParameters) { throw new IllegalArgumentException("Expecting " + expectedParameters + " parameters"); } Options options = new Options(); - int maxSize = Integer.parseInt(args[1]) & ~7; // multiple of 8 + Ln.Level level = Ln.Level.valueOf(args[1].toUpperCase()); + options.setLogLevel(level); + + int maxSize = Integer.parseInt(args[2]) & ~7; // multiple of 8 options.setMaxSize(maxSize); - int bitRate = Integer.parseInt(args[2]); + int bitRate = Integer.parseInt(args[3]); options.setBitRate(bitRate); - int maxFps = Integer.parseInt(args[3]); + int maxFps = Integer.parseInt(args[4]); options.setMaxFps(maxFps); - int lockedVideoOrientation = Integer.parseInt(args[4]); + int lockedVideoOrientation = Integer.parseInt(args[5]); options.setLockedVideoOrientation(lockedVideoOrientation); // use "adb forward" instead of "adb tunnel"? (so the server must listen) - boolean tunnelForward = Boolean.parseBoolean(args[5]); + boolean tunnelForward = Boolean.parseBoolean(args[6]); options.setTunnelForward(tunnelForward); - Rect crop = parseCrop(args[6]); + Rect crop = parseCrop(args[7]); options.setCrop(crop); - boolean sendFrameMeta = Boolean.parseBoolean(args[7]); + boolean sendFrameMeta = Boolean.parseBoolean(args[8]); options.setSendFrameMeta(sendFrameMeta); - boolean control = Boolean.parseBoolean(args[8]); + boolean control = Boolean.parseBoolean(args[9]); options.setControl(control); - int displayId = Integer.parseInt(args[9]); + int displayId = Integer.parseInt(args[10]); options.setDisplayId(displayId); - boolean showTouches = Boolean.parseBoolean(args[10]); + boolean showTouches = Boolean.parseBoolean(args[11]); options.setShowTouches(showTouches); - boolean stayAwake = Boolean.parseBoolean(args[11]); + boolean stayAwake = Boolean.parseBoolean(args[12]); options.setStayAwake(stayAwake); - String codecOptions = args[12]; + String codecOptions = args[13]; options.setCodecOptions(codecOptions); return options; @@ -215,6 +218,9 @@ public void uncaughtException(Thread t, Throwable e) { }); Options options = createOptions(args); + + Ln.initLogLevel(options.getLogLevel()); + scrcpy(options); } }