Skip to content

Commit

Permalink
Add --verbosity=verbose log level
Browse files Browse the repository at this point in the history
  • Loading branch information
intgr committed Jun 17, 2021
1 parent 506f918 commit 2e392db
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 2 deletions.
7 changes: 6 additions & 1 deletion app/src/cli.c
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ scrcpy_print_usage(const char *arg0) {
"\n"
#endif
" -V, --verbosity value\n"
" Set the log level (debug, info, warn or error).\n"
" Set the log level (verbose, debug, info, warn or error).\n"
#ifndef NDEBUG
" Default is debug.\n"
#else
Expand Down Expand Up @@ -505,6 +505,11 @@ parse_display_id(const char *s, uint32_t *display_id) {

static bool
parse_log_level(const char *s, enum sc_log_level *log_level) {
if (!strcmp(s, "verbose")) {
*log_level = SC_LOG_LEVEL_VERBOSE;
return true;
}

if (!strcmp(s, "debug")) {
*log_level = SC_LOG_LEVEL_DEBUG;
return true;
Expand Down
2 changes: 2 additions & 0 deletions app/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ print_version(void) {
static SDL_LogPriority
convert_log_level_to_sdl(enum sc_log_level level) {
switch (level) {
case SC_LOG_LEVEL_VERBOSE:
return SDL_LOG_PRIORITY_VERBOSE;
case SC_LOG_LEVEL_DEBUG:
return SDL_LOG_PRIORITY_DEBUG;
case SC_LOG_LEVEL_INFO:
Expand Down
1 change: 1 addition & 0 deletions app/src/scrcpy.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <stdint.h>

enum sc_log_level {
SC_LOG_LEVEL_VERBOSE,
SC_LOG_LEVEL_DEBUG,
SC_LOG_LEVEL_INFO,
SC_LOG_LEVEL_WARN,
Expand Down
2 changes: 2 additions & 0 deletions app/src/server.c
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,8 @@ enable_tunnel_any_port(struct server *server, struct sc_port_range port_range,
static const char *
log_level_to_server_string(enum sc_log_level level) {
switch (level) {
case SC_LOG_LEVEL_VERBOSE:
return "verbose";
case SC_LOG_LEVEL_DEBUG:
return "debug";
case SC_LOG_LEVEL_INFO:
Expand Down
9 changes: 8 additions & 1 deletion server/src/main/java/com/genymobile/scrcpy/Ln.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public final class Ln {
private static final String PREFIX = "[server] ";

enum Level {
DEBUG, INFO, WARN, ERROR
VERBOSE, DEBUG, INFO, WARN, ERROR
}

private static Level threshold = Level.INFO;
Expand All @@ -36,6 +36,13 @@ public static boolean isEnabled(Level level) {
return level.ordinal() >= threshold.ordinal();
}

public static void v(String message) {
if (isEnabled(Level.VERBOSE)) {
Log.v(TAG, message);
System.out.println(PREFIX + "VERBOSE: " + message);
}
}

public static void d(String message) {
if (isEnabled(Level.DEBUG)) {
Log.d(TAG, message);
Expand Down
1 change: 1 addition & 0 deletions server/src/main/java/com/genymobile/scrcpy/Server.java
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,7 @@ public void uncaughtException(Thread t, Throwable e) {
Options options = createOptions(args);

Ln.initLogLevel(options.getLogLevel());
Ln.v("Using verbose log level");

scrcpy(options);
}
Expand Down

0 comments on commit 2e392db

Please sign in to comment.