Configure server verbosity from the client

Send the requested log level from the client.

This paves the way to configure it via a command-line argument.
This commit is contained in:
Romain Vimont 2020-05-24 21:08:22 +02:00
parent 56bff2f718
commit 3df63c579d
4 changed files with 45 additions and 14 deletions

View file

@ -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,

View file

@ -15,12 +15,23 @@ public final class Ln {
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.
* <p>
* 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();
}

View file

@ -3,6 +3,7 @@ package com.genymobile.scrcpy;
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;
}

View file

@ -119,48 +119,51 @@ public final class Server {
"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 final class Server {
});
Options options = createOptions(args);
Ln.initLogLevel(options.getLogLevel());
scrcpy(options);
}
}