From 01c362eadc2235a00414501cfccdc485f40cd9d8 Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Thu, 30 Aug 2018 11:07:51 +1000 Subject: [PATCH] ratbagd: log the device list by default Without --verbose ratbagd just starts up with no message whatsoever. It's hard to tell if any devices are supported or if the server just hangs. Let's log the devices detected by default, at least that way we get some feedback. Signed-off-by: Peter Hutterer --- ratbagd/ratbagd-device.c | 8 ++++---- ratbagd/ratbagd.c | 34 +++++++++++++++++++++++++--------- ratbagd/ratbagd.h | 1 + tools/toolbox.py | 2 ++ 4 files changed, 32 insertions(+), 13 deletions(-) diff --git a/ratbagd/ratbagd-device.c b/ratbagd/ratbagd-device.c index 6f2b9447..6e1e9eea 100644 --- a/ratbagd/ratbagd-device.c +++ b/ratbagd/ratbagd-device.c @@ -323,10 +323,10 @@ int ratbagd_device_new(struct ratbagd_device **out, device->n_profiles = ratbag_device_get_num_profiles(device->lib_device); device->profiles = zalloc(device->n_profiles * sizeof(*device->profiles)); - log_verbose("%s: \"%s\", %d profiles\n", - sysname, - ratbag_device_get_name(lib_device), - device->n_profiles); + log_info("%s: \"%s\", %d profiles\n", + sysname, + ratbag_device_get_name(lib_device), + device->n_profiles); for (i = 0; i < device->n_profiles; ++i) { profile = ratbag_device_get_profile(device->lib_device, i); diff --git a/ratbagd/ratbagd.c b/ratbagd/ratbagd.c index ee2bcaee..ef982614 100644 --- a/ratbagd/ratbagd.c +++ b/ratbagd/ratbagd.c @@ -42,8 +42,12 @@ #include "ratbagd-test.h" -static bool verbose = false; -static bool verbose_raw = false; +enum log_level { + LL_QUIET = 1, + LL_INFO, + LL_VERBOSE, + LL_RAW, +} log_level = LL_INFO; static const char *SVG_THEMES[] = { "default", @@ -51,13 +55,23 @@ static const char *SVG_THEMES[] = { NULL }; +void log_info(const char *fmt, ...) +{ + va_list args; + + va_start(args, fmt); + if (log_level >= LL_INFO) + vprintf(fmt, args); + va_end(args); +} + void log_verbose(const char *fmt, ...) { va_list args; va_start(args, fmt); - if (verbose) + if (log_level >= LL_VERBOSE) vprintf(fmt, args); va_end(args); } @@ -376,10 +390,10 @@ static int ratbagd_new(struct ratbagd **out) if (!ctx->lib_ctx) return -ENOMEM; - if (verbose_raw) + if (log_level >= LL_RAW) ratbag_log_set_priority(ctx->lib_ctx, RATBAG_LOG_PRIORITY_RAW); - else if (verbose) + else if (log_level >= LL_VERBOSE) ratbag_log_set_priority(ctx->lib_ctx, RATBAG_LOG_PRIORITY_DEBUG); @@ -525,12 +539,14 @@ int main(int argc, char *argv[]) #endif if (argc > 1) { - if (streq(argv[1], "--verbose=raw")) { - verbose_raw = true; + if (streq(argv[1], "--quiet")) { + log_level = LL_QUIET; + } else if (streq(argv[1], "--verbose=raw")) { + log_level = LL_RAW; } else if (streq(argv[1], "--verbose")) { - verbose = true; + log_level = LL_VERBOSE; } else { - fprintf(stderr, "Usage: %s [--verbose[=raw]]\n", + fprintf(stderr, "Usage: %s [--quiet | --verbose[=raw]]\n", program_invocation_short_name); r = -EINVAL; goto exit; diff --git a/ratbagd/ratbagd.h b/ratbagd/ratbagd.h index 2c534b75..04311b36 100644 --- a/ratbagd/ratbagd.h +++ b/ratbagd/ratbagd.h @@ -54,6 +54,7 @@ struct ratbagd_resolution; struct ratbagd_button; struct ratbagd_led; +void log_info(const char *fmt, ...) _printf_(1, 2); void log_verbose(const char *fmt, ...) _printf_(1, 2); void log_error(const char *fmt, ...) _printf_(1, 2); diff --git a/tools/toolbox.py b/tools/toolbox.py index 7d742d02..3758e568 100644 --- a/tools/toolbox.py +++ b/tools/toolbox.py @@ -75,6 +75,8 @@ def start_ratbagd(verbosity=0): args.append('--verbose=raw') elif verbosity >= 2: args.append('--verbose') + elif verbosity == 0: + args.append('--quiet') ratbagd_process = subprocess.Popen(args, shell=False, stdout=sys.stdout, stderr=sys.stderr)