aboutsummaryrefslogtreecommitdiff
path: root/client.c
diff options
context:
space:
mode:
authorDaniel Eklöf <daniel@ekloef.se>2021-02-11 18:00:09 +0000
committerDaniel Eklöf <daniel@ekloef.se>2021-02-11 18:00:09 +0000
commitda7da4cba51a6444d1fce8fc8767f25cbe38b351 (patch)
tree753c75d7f159fb82719cad42efd3144070a7f1d7 /client.c
parentMerge branch 'fdm-signal-handling' (diff)
parentmain: client: factor out some common code for "--log-level" option (diff)
Merge branch 'log-level'
Closes #337
Diffstat (limited to 'client.c')
-rw-r--r--client.c47
1 files changed, 33 insertions, 14 deletions
diff --git a/client.c b/client.c
index dead7117..bf9264ee 100644
--- a/client.c
+++ b/client.c
@@ -17,6 +17,8 @@
#include "client-protocol.h"
#include "debug.h"
#include "foot-features.h"
+#include "macros.h"
+#include "util.h"
#include "version.h"
#include "xmalloc.h"
@@ -44,18 +46,19 @@ print_usage(const char *prog_name)
printf("Usage: %s [OPTIONS...] [ARGS...]\n", prog_name);
printf("\n");
printf("Options:\n");
- printf(" -t,--term=TERM value to set the environment variable TERM to (foot)\n"
- " --title=TITLE initial window title (foot)\n"
- " -a,--app-id=ID window application ID (foot)\n"
- " -w,--window-size-pixels=WIDTHxHEIGHT initial width and height, in pixels\n"
- " -W,--window-size-chars=WIDTHxHEIGHT initial width and height, in characters\n"
- " --maximized start in maximized mode\n"
- " --fullscreen start in fullscreen mode\n"
- " --login-shell start shell as a login shell\n"
- " -s,--server-socket=PATH path to the server UNIX domain socket (default=$XDG_RUNTIME_DIR/foot-$WAYLAND_DISPLAY.sock)\n"
- " --hold remain open after child process exits\n"
- " -l,--log-colorize=[never|always|auto] enable/disable colorization of log output on stderr\n"
- " -v,--version show the version number and quit\n");
+ printf(" -t,--term=TERM value to set the environment variable TERM to (foot)\n"
+ " --title=TITLE initial window title (foot)\n"
+ " -a,--app-id=ID window application ID (foot)\n"
+ " -w,--window-size-pixels=WIDTHxHEIGHT initial width and height, in pixels\n"
+ " -W,--window-size-chars=WIDTHxHEIGHT initial width and height, in characters\n"
+ " --maximized start in maximized mode\n"
+ " --fullscreen start in fullscreen mode\n"
+ " --login-shell start shell as a login shell\n"
+ " -s,--server-socket=PATH path to the server UNIX domain socket (default=$XDG_RUNTIME_DIR/foot-$WAYLAND_DISPLAY.sock)\n"
+ " --hold remain open after child process exits\n"
+ " -d,---log-level={info|warning|error} log level (info)\n"
+ " -l,--log-colorize=[{never|always|auto}] enable/disable colorization of log output on stderr\n"
+ " -v,--version show the version number and quit\n");
}
int
@@ -76,6 +79,7 @@ main(int argc, char *const *argv)
{"login-shell", no_argument, NULL, 'L'},
{"server-socket", required_argument, NULL, 's'},
{"hold", no_argument, NULL, 'H'},
+ {"log-level", required_argument, NULL, 'd'},
{"log-colorize", optional_argument, NULL, 'l'},
{"version", no_argument, NULL, 'v'},
{"help", no_argument, NULL, 'h'},
@@ -89,6 +93,7 @@ main(int argc, char *const *argv)
unsigned width = 0;
unsigned height = 0;
const char *server_socket_path = NULL;
+ enum log_class log_level = LOG_CLASS_INFO;
enum log_colorize log_colorize = LOG_COLORIZE_AUTO;
bool login_shell = false;
bool maximized = false;
@@ -96,7 +101,7 @@ main(int argc, char *const *argv)
bool hold = false;
while (true) {
- int c = getopt_long(argc, argv, "+t:T:a:w:W:mFLs:Hl::vh", longopts, NULL);
+ int c = getopt_long(argc, argv, "+t:T:a:w:W:mFLs:Hd:l::vh", longopts, NULL);
if (c == -1)
break;
@@ -151,6 +156,20 @@ main(int argc, char *const *argv)
hold = true;
break;
+ case 'd': {
+ int lvl = log_level_from_string(optarg);
+ if (unlikely(lvl < 0)) {
+ fprintf(
+ stderr,
+ "-d,--log-level: %s: argument must be one of %s\n",
+ optarg,
+ log_level_string_hint());
+ return EXIT_FAILURE;
+ }
+ log_level = lvl;
+ break;
+ }
+
case 'l':
if (optarg == NULL || strcmp(optarg, "auto") == 0)
log_colorize = LOG_COLORIZE_AUTO;
@@ -180,7 +199,7 @@ main(int argc, char *const *argv)
argc -= optind;
argv += optind;
- log_init(log_colorize, false, LOG_FACILITY_USER, LOG_CLASS_WARNING);
+ log_init(log_colorize, false, LOG_FACILITY_USER, log_level);
/* malloc:ed and needs to be in scope of all goto's */
char *cwd = NULL;