mirror of
https://codeberg.org/dnkl/foot.git
synced 2026-03-15 05:33:58 -04:00
main: add -d,--log-level=[debug,info,warning,error]
This commit is contained in:
parent
208014d6c9
commit
ca3974cc24
1 changed files with 59 additions and 20 deletions
79
main.c
79
main.c
|
|
@ -58,24 +58,25 @@ print_usage(const char *prog_name)
|
||||||
"Usage: %s [OPTIONS...] command [ARGS...]\n"
|
"Usage: %s [OPTIONS...] command [ARGS...]\n"
|
||||||
"\n"
|
"\n"
|
||||||
"Options:\n"
|
"Options:\n"
|
||||||
" -c,--config=PATH load configuration from PATH ($XDG_CONFIG_HOME/foot/foot.ini)\n"
|
" -c,--config=PATH load configuration from PATH ($XDG_CONFIG_HOME/foot/foot.ini)\n"
|
||||||
" --check-config verify configuration, exit with 0 if ok, otherwise exit with 1\n"
|
" --check-config verify configuration, exit with 0 if ok, otherwise exit with 1\n"
|
||||||
" -f,--font=FONT comma separated list of fonts in fontconfig format (monospace)\n"
|
" -f,--font=FONT comma separated list of fonts in fontconfig format (monospace)\n"
|
||||||
" -t,--term=TERM value to set the environment variable TERM to (foot)\n"
|
" -t,--term=TERM value to set the environment variable TERM to (foot)\n"
|
||||||
" --title=TITLE initial window title (foot)\n"
|
" --title=TITLE initial window title (foot)\n"
|
||||||
" -a,--app-id=ID window application ID (foot)\n"
|
" -a,--app-id=ID window application ID (foot)\n"
|
||||||
" --maximized start in maximized mode\n"
|
" --maximized start in maximized mode\n"
|
||||||
" --fullscreen start in fullscreen mode\n"
|
" --fullscreen start in fullscreen mode\n"
|
||||||
" --login-shell start shell as a login shell\n"
|
" --login-shell start shell as a login shell\n"
|
||||||
" -w,--window-size-pixels=WIDTHxHEIGHT initial width and height, in pixels\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"
|
" -W,--window-size-chars=WIDTHxHEIGHT initial width and height, in characters\n"
|
||||||
" -s,--server[=PATH] run as a server (use 'footclient' to start terminals).\n"
|
" -s,--server[=PATH] run as a server (use 'footclient' to start terminals).\n"
|
||||||
" Without PATH, $XDG_RUNTIME_DIR/foot-$WAYLAND_DISPLAY.sock will be used.\n"
|
" Without PATH, $XDG_RUNTIME_DIR/foot-$WAYLAND_DISPLAY.sock will be used.\n"
|
||||||
" --hold remain open after child process exits\n"
|
" --hold remain open after child process exits\n"
|
||||||
" -p,--print-pid=FILE|FD print PID to file or FD (only applicable in server mode)\n"
|
" -p,--print-pid=FILE|FD print PID to file or FD (only applicable in server mode)\n"
|
||||||
" -l,--log-colorize=[never|always|auto] enable/disable colorization of log output on stderr\n"
|
" -d,--log-level={info|warning|error} log level (info)\n"
|
||||||
" -s,--log-no-syslog disable syslog logging (only applicable in server mode)\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",
|
" -s,--log-no-syslog disable syslog logging (only applicable in server mode)\n"
|
||||||
|
" -v,--version show the version number and quit\n",
|
||||||
prog_name, prog_name);
|
prog_name, prog_name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -171,6 +172,7 @@ main(int argc, char *const *argv)
|
||||||
{"fullscreen", no_argument, NULL, 'F'},
|
{"fullscreen", no_argument, NULL, 'F'},
|
||||||
{"presentation-timings", no_argument, NULL, 'P'}, /* Undocumented */
|
{"presentation-timings", no_argument, NULL, 'P'}, /* Undocumented */
|
||||||
{"print-pid", required_argument, NULL, 'p'},
|
{"print-pid", required_argument, NULL, 'p'},
|
||||||
|
{"log-level", required_argument, NULL, 'd'},
|
||||||
{"log-colorize", optional_argument, NULL, 'l'},
|
{"log-colorize", optional_argument, NULL, 'l'},
|
||||||
{"log-no-syslog", no_argument, NULL, 'S'},
|
{"log-no-syslog", no_argument, NULL, 'S'},
|
||||||
{"version", no_argument, NULL, 'v'},
|
{"version", no_argument, NULL, 'v'},
|
||||||
|
|
@ -196,12 +198,13 @@ main(int argc, char *const *argv)
|
||||||
bool fullscreen = false;
|
bool fullscreen = false;
|
||||||
bool unlink_pid_file = false;
|
bool unlink_pid_file = false;
|
||||||
const char *pid_file = NULL;
|
const char *pid_file = NULL;
|
||||||
|
enum log_class log_level = LOG_CLASS_INFO;
|
||||||
enum log_colorize log_colorize = LOG_COLORIZE_AUTO;
|
enum log_colorize log_colorize = LOG_COLORIZE_AUTO;
|
||||||
bool log_syslog = true;
|
bool log_syslog = true;
|
||||||
user_notifications_t user_notifications = tll_init();
|
user_notifications_t user_notifications = tll_init();
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
int c = getopt_long(argc, argv, "+c:Ct:T:a:Lf:w:W:s::HmFPp:l::Svh", longopts, NULL);
|
int c = getopt_long(argc, argv, "+c:Ct:T:a:Lf:w:W:s::HmFPp:d:l::Svh", longopts, NULL);
|
||||||
if (c == -1)
|
if (c == -1)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|
@ -306,6 +309,42 @@ main(int argc, char *const *argv)
|
||||||
pid_file = optarg;
|
pid_file = optarg;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case 'd': {
|
||||||
|
static const char *log_level_map[] = {
|
||||||
|
#if defined(_DEBUG)
|
||||||
|
[LOG_CLASS_DEBUG] = "debug",
|
||||||
|
#endif
|
||||||
|
[LOG_CLASS_INFO] = "info",
|
||||||
|
[LOG_CLASS_WARNING] = "warning",
|
||||||
|
[LOG_CLASS_ERROR] = "error",
|
||||||
|
};
|
||||||
|
|
||||||
|
bool valid_log_level = false;
|
||||||
|
for (size_t i = 0; i < ALEN(log_level_map); i++) {
|
||||||
|
if (strcmp(optarg, log_level_map[i]) == 0) {
|
||||||
|
log_level = i;
|
||||||
|
valid_log_level = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!valid_log_level) {
|
||||||
|
fprintf(
|
||||||
|
stderr, "-d,--log-level: %s: argument must be one of ",
|
||||||
|
optarg);
|
||||||
|
|
||||||
|
for (size_t i = 0; i < ALEN(log_level_map); i++) {
|
||||||
|
fprintf(stderr, "'%s'%s",
|
||||||
|
log_level_map[i],
|
||||||
|
i < ALEN(log_level_map) - 1 ? " , " : "");
|
||||||
|
}
|
||||||
|
fprintf(stderr, "\n");
|
||||||
|
|
||||||
|
return EXIT_FAILURE;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
case 'l':
|
case 'l':
|
||||||
if (optarg == NULL || strcmp(optarg, "auto") == 0)
|
if (optarg == NULL || strcmp(optarg, "auto") == 0)
|
||||||
log_colorize = LOG_COLORIZE_AUTO;
|
log_colorize = LOG_COLORIZE_AUTO;
|
||||||
|
|
@ -337,7 +376,7 @@ main(int argc, char *const *argv)
|
||||||
}
|
}
|
||||||
|
|
||||||
log_init(log_colorize, as_server && log_syslog,
|
log_init(log_colorize, as_server && log_syslog,
|
||||||
as_server ? LOG_FACILITY_DAEMON : LOG_FACILITY_USER, LOG_CLASS_WARNING);
|
as_server ? LOG_FACILITY_DAEMON : LOG_FACILITY_USER, log_level);
|
||||||
|
|
||||||
argc -= optind;
|
argc -= optind;
|
||||||
argv += optind;
|
argv += optind;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue