mirror of
https://codeberg.org/dnkl/foot.git
synced 2026-03-18 05:34:02 -04:00
log: add LOG_CLASS_NONE and use as initializer for log_level
This means that logging will be completely disabled until log_init()
has been called, which is useful to prevent log spam when running
UNITTEST{} blocks in debug builds.
Note that this doesn't change the default log level at runtime, which
was already being set to LOG_CLASS_INFO in main.c and client.c.
The new log level is also exposed to the command-line interface as
`--log-level=none`, which allows disabling logging entirely.
This commit is contained in:
parent
0ff8f72a9d
commit
5dca0458a0
14 changed files with 113 additions and 93 deletions
|
|
@ -28,7 +28,11 @@
|
||||||
|
|
||||||
|
|
||||||
## Unreleased
|
## Unreleased
|
||||||
|
|
||||||
### Added
|
### Added
|
||||||
|
|
||||||
|
* `--log-level=none` command-line option.
|
||||||
|
|
||||||
### Changed
|
### Changed
|
||||||
### Deprecated
|
### Deprecated
|
||||||
### Removed
|
### Removed
|
||||||
|
|
@ -40,6 +44,8 @@
|
||||||
### Security
|
### Security
|
||||||
### Contributors
|
### Contributors
|
||||||
|
|
||||||
|
* [craigbarnes](https://codeberg.org/craigbarnes)
|
||||||
|
|
||||||
|
|
||||||
## 1.8.0
|
## 1.8.0
|
||||||
|
|
||||||
|
|
|
||||||
32
client.c
32
client.c
|
|
@ -58,22 +58,22 @@ print_usage(const char *prog_name)
|
||||||
printf("Usage: %s [OPTIONS...] command [ARGS...]\n", prog_name);
|
printf("Usage: %s [OPTIONS...] command [ARGS...]\n", prog_name);
|
||||||
printf("\n");
|
printf("\n");
|
||||||
printf("Options:\n");
|
printf("Options:\n");
|
||||||
printf(" -t,--term=TERM value to set the environment variable TERM to (foot)\n"
|
printf(" -t,--term=TERM value to set the environment variable TERM to (foot)\n"
|
||||||
" -T,--title=TITLE initial window title (foot)\n"
|
" -T,--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"
|
||||||
" -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"
|
||||||
" -m,--maximized start in maximized mode\n"
|
" -m,--maximized start in maximized mode\n"
|
||||||
" -F,--fullscreen start in fullscreen mode\n"
|
" -F,--fullscreen start in fullscreen mode\n"
|
||||||
" -L,--login-shell start shell as a login shell\n"
|
" -L,--login-shell start shell as a login shell\n"
|
||||||
" -D,--working-directory=DIR directory to start in (CWD)\n"
|
" -D,--working-directory=DIR directory to start in (CWD)\n"
|
||||||
" -s,--server-socket=PATH path to the server UNIX domain socket (default=$XDG_RUNTIME_DIR/foot-$WAYLAND_DISPLAY.sock)\n"
|
" -s,--server-socket=PATH path to the server UNIX domain socket (default=$XDG_RUNTIME_DIR/foot-$WAYLAND_DISPLAY.sock)\n"
|
||||||
" -H,--hold remain open after child process exits\n"
|
" -H,--hold remain open after child process exits\n"
|
||||||
" -N,--no-wait detach the client process from the running terminal, exiting immediately\n"
|
" -N,--no-wait detach the client process from the running terminal, exiting immediately\n"
|
||||||
" -o,--override=[section.]key=value override configuration option\n"
|
" -o,--override=[section.]key=value override configuration option\n"
|
||||||
" -d,--log-level={info|warning|error} log level (info)\n"
|
" -d,--log-level={info|warning|error|none} log level (info)\n"
|
||||||
" -l,--log-colorize=[{never|always|auto}] enable/disable colorization of log output on stderr\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");
|
" -v,--version show the version number and quit\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool NOINLINE
|
static bool NOINLINE
|
||||||
|
|
|
||||||
|
|
@ -68,7 +68,7 @@ _foot()
|
||||||
which fc-list > /dev/null || return 1
|
which fc-list > /dev/null || return 1
|
||||||
COMPREPLY=( $(compgen -W "$(fc-list : family | sed 's/,/\n/g' | uniq | tr -d ' ')" -- ${cur}) )
|
COMPREPLY=( $(compgen -W "$(fc-list : family | sed 's/,/\n/g' | uniq | tr -d ' ')" -- ${cur}) )
|
||||||
elif [[ ${prev} == '--log-level' ]] ; then
|
elif [[ ${prev} == '--log-level' ]] ; then
|
||||||
COMPREPLY=( $(compgen -W "error warning info" -- ${cur}) )
|
COMPREPLY=( $(compgen -W "none error warning info" -- ${cur}) )
|
||||||
elif [[ ${prev} == '--log-colorize' ]] ; then
|
elif [[ ${prev} == '--log-colorize' ]] ; then
|
||||||
COMPREPLY=( $(compgen -W "never always auto" -- ${cur}) )
|
COMPREPLY=( $(compgen -W "never always auto" -- ${cur}) )
|
||||||
elif [[ ${prev} =~ ^(--app-id|--help|--override|--title|--version|--window-size-chars|--window-size-pixels|--check-config)$ ]] ; then
|
elif [[ ${prev} =~ ^(--app-id|--help|--override|--title|--version|--window-size-chars|--window-size-pixels|--check-config)$ ]] ; then
|
||||||
|
|
|
||||||
|
|
@ -59,7 +59,7 @@ _footclient()
|
||||||
which toe > /dev/null || return 1
|
which toe > /dev/null || return 1
|
||||||
COMPREPLY=( $(compgen -W "$(toe -a | awk '$1 ~ /[+]/ {next}; {print $1}')" -- ${cur}) )
|
COMPREPLY=( $(compgen -W "$(toe -a | awk '$1 ~ /[+]/ {next}; {print $1}')" -- ${cur}) )
|
||||||
elif [[ ${prev} == '--log-level' ]] ; then
|
elif [[ ${prev} == '--log-level' ]] ; then
|
||||||
COMPREPLY=( $(compgen -W "error warning info" -- ${cur}) )
|
COMPREPLY=( $(compgen -W "none error warning info" -- ${cur}) )
|
||||||
elif [[ ${prev} == '--log-colorize' ]] ; then
|
elif [[ ${prev} == '--log-colorize' ]] ; then
|
||||||
COMPREPLY=( $(compgen -W "never always auto" -- ${cur}) )
|
COMPREPLY=( $(compgen -W "never always auto" -- ${cur}) )
|
||||||
elif [[ ${prev} =~ ^(--app-id|--help|--override|--title|--version|--window-size-chars|--window-size-pixels|)$ ]] ; then
|
elif [[ ${prev} =~ ^(--app-id|--help|--override|--title|--version|--window-size-chars|--window-size-pixels|)$ ]] ; then
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,7 @@ complete -c foot -x -s W -l window-size-chars
|
||||||
complete -c foot -F -s s -l server -d "run as server; open terminals by running footclient"
|
complete -c foot -F -s s -l server -d "run as server; open terminals by running footclient"
|
||||||
complete -c foot -s H -l hold -d "remain open after child process exits"
|
complete -c foot -s H -l hold -d "remain open after child process exits"
|
||||||
complete -c foot -r -s p -l print-pid -d "print PID to this file or FD when up and running (server mode only)"
|
complete -c foot -r -s p -l print-pid -d "print PID to this file or FD when up and running (server mode only)"
|
||||||
complete -c foot -x -s d -l log-level -a "info warning error" -d "log-level (info)"
|
complete -c foot -x -s d -l log-level -a "info warning error none" -d "log-level (info)"
|
||||||
complete -c foot -x -s l -l log-colorize -a "always never auto" -d "enable or disable colorization of log output on stderr"
|
complete -c foot -x -s l -l log-colorize -a "always never auto" -d "enable or disable colorization of log output on stderr"
|
||||||
complete -c foot -s S -l log-no-syslog -d "disable syslog logging (server mode only)"
|
complete -c foot -s S -l log-no-syslog -d "disable syslog logging (server mode only)"
|
||||||
complete -c foot -s v -l version -d "show the version number and quit"
|
complete -c foot -s v -l version -d "show the version number and quit"
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,7 @@ complete -c footclient -F -s s -l server-socket
|
||||||
complete -c footclient -s H -l hold -d "remain open after child process exits"
|
complete -c footclient -s H -l hold -d "remain open after child process exits"
|
||||||
complete -c footclient -s N -l no-wait -d "detach the client process from the running terminal, exiting immediately"
|
complete -c footclient -s N -l no-wait -d "detach the client process from the running terminal, exiting immediately"
|
||||||
complete -c footclient -x -s o -l override -d "configuration option to override, in form SECTION.KEY=VALUE"
|
complete -c footclient -x -s o -l override -d "configuration option to override, in form SECTION.KEY=VALUE"
|
||||||
complete -c footclient -x -s d -l log-level -a "info warning error" -d "log-level (info)"
|
complete -c footclient -x -s d -l log-level -a "info warning error none" -d "log-level (info)"
|
||||||
complete -c footclient -x -s l -l log-colorize -a "always never auto" -d "enable or disable colorization of log output on stderr"
|
complete -c footclient -x -s l -l log-colorize -a "always never auto" -d "enable or disable colorization of log output on stderr"
|
||||||
complete -c footclient -s v -l version -d "show the version number and quit"
|
complete -c footclient -s v -l version -d "show the version number and quit"
|
||||||
complete -c footclient -s h -l help -d "show help message and quit"
|
complete -c footclient -s h -l help -d "show help message and quit"
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,7 @@ _arguments \
|
||||||
'(-s --server)'{-s,--server}'[run as server; open terminals by running footclient]:server:_files' \
|
'(-s --server)'{-s,--server}'[run as server; open terminals by running footclient]:server:_files' \
|
||||||
'(-H --hold)'{-H,--hold}'[remain open after child process exits]' \
|
'(-H --hold)'{-H,--hold}'[remain open after child process exits]' \
|
||||||
'(-p --print-pid)'{-p,--print-pid}'[print PID to this file or FD when up and running (server mode only)]:pidfile:_files' \
|
'(-p --print-pid)'{-p,--print-pid}'[print PID to this file or FD when up and running (server mode only)]:pidfile:_files' \
|
||||||
'(-d --log-level)'{-d,--log-level}'[log level (info)]:loglevel:(info warning error)' \
|
'(-d --log-level)'{-d,--log-level}'[log level (info)]:loglevel:(info warning error none)' \
|
||||||
'(-l --log-colorize)'{-l,--log-colorize}'[enable or disable colorization of log output on stderr]:logcolor:(never always auto)' \
|
'(-l --log-colorize)'{-l,--log-colorize}'[enable or disable colorization of log output on stderr]:logcolor:(never always auto)' \
|
||||||
'(-S --log-no-syslog)'{-s,--log-no-syslog}'[disable syslog logging (server mode only)]' \
|
'(-S --log-no-syslog)'{-s,--log-no-syslog}'[disable syslog logging (server mode only)]' \
|
||||||
'(-v --version)'{-v,--version}'[show the version number and quit]' \
|
'(-v --version)'{-v,--version}'[show the version number and quit]' \
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,7 @@ _arguments \
|
||||||
'(-H --hold)'{-H,--hold}'[remain open after child process exits]' \
|
'(-H --hold)'{-H,--hold}'[remain open after child process exits]' \
|
||||||
'(-N --no-wait)'{-N,--no-wait}'[detach the client process from the running terminal, exiting immediately]' \
|
'(-N --no-wait)'{-N,--no-wait}'[detach the client process from the running terminal, exiting immediately]' \
|
||||||
'(-o --override)'{-o,--override}'[configuration option to override, in form SECTION.KEY=VALUE]:()' \
|
'(-o --override)'{-o,--override}'[configuration option to override, in form SECTION.KEY=VALUE]:()' \
|
||||||
'(-d --log-level)'{-d,--log-level}'[log level (info)]:loglevel:(info warning error)' \
|
'(-d --log-level)'{-d,--log-level}'[log level (info)]:loglevel:(info warning error none)' \
|
||||||
'(-l --log-colorize)'{-l,--log-colorize}'[enable or disable colorization of log output on stderr]:logcolor:(never always auto)' \
|
'(-l --log-colorize)'{-l,--log-colorize}'[enable or disable colorization of log output on stderr]:logcolor:(never always auto)' \
|
||||||
'(-v --version)'{-v,--version}'[show the version number and quit]' \
|
'(-v --version)'{-v,--version}'[show the version number and quit]' \
|
||||||
'(-h --help)'{-h,--help}'[show help message and quit]' \
|
'(-h --help)'{-h,--help}'[show help message and quit]' \
|
||||||
|
|
|
||||||
6
config.c
6
config.c
|
|
@ -103,8 +103,10 @@ log_and_notify(struct config *conf, enum log_class log_class,
|
||||||
|
|
||||||
case LOG_CLASS_INFO:
|
case LOG_CLASS_INFO:
|
||||||
case LOG_CLASS_DEBUG:
|
case LOG_CLASS_DEBUG:
|
||||||
BUG("unsupported log class: %d", log_class);
|
case LOG_CLASS_NONE:
|
||||||
break;
|
default:
|
||||||
|
BUG("unsupported log class: %d", (int)log_class);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
va_list va1, va2;
|
va_list va1, va2;
|
||||||
|
|
|
||||||
|
|
@ -126,7 +126,7 @@ the foot command line
|
||||||
|
|
||||||
This option can only be used in combination with *-s*,*--server*.
|
This option can only be used in combination with *-s*,*--server*.
|
||||||
|
|
||||||
*-d*,*--log-level*={*info*,*warning*,*error*}
|
*-d*,*--log-level*={*info*,*warning*,*error*,*none*}
|
||||||
Log level, used both for log output on stderr as well as
|
Log level, used both for log output on stderr as well as
|
||||||
syslog. Default: _info_.
|
syslog. Default: _info_.
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -69,7 +69,7 @@ terminal has terminated.
|
||||||
Override an option set in the configuration file. If _SECTION_ is not
|
Override an option set in the configuration file. If _SECTION_ is not
|
||||||
given, defaults to _main_.
|
given, defaults to _main_.
|
||||||
|
|
||||||
*-d*,*--log-level*={*info*,*warning*,*error*}
|
*-d*,*--log-level*={*info*,*warning*,*error*,*none*}
|
||||||
Log level, used both for log output on stderr as well as
|
Log level, used both for log output on stderr as well as
|
||||||
syslog. Default: _info_.
|
syslog. Default: _info_.
|
||||||
|
|
||||||
|
|
|
||||||
88
log.c
88
log.c
|
|
@ -3,6 +3,7 @@
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
|
#include <stdint.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
@ -15,15 +16,19 @@
|
||||||
|
|
||||||
static bool colorize = false;
|
static bool colorize = false;
|
||||||
static bool do_syslog = true;
|
static bool do_syslog = true;
|
||||||
static enum log_class log_level = LOG_CLASS_INFO;
|
static enum log_class log_level = LOG_CLASS_NONE;
|
||||||
|
|
||||||
static const char log_level_map[][8] = {
|
static const struct {
|
||||||
[LOG_CLASS_ERROR] = "error",
|
const char name[8];
|
||||||
[LOG_CLASS_WARNING] = "warning",
|
const char log_prefix[7];
|
||||||
[LOG_CLASS_INFO] = "info",
|
uint8_t color;
|
||||||
#if defined(_DEBUG)
|
int syslog_equivalent;
|
||||||
[LOG_CLASS_DEBUG] = "debug",
|
} log_level_map[] = {
|
||||||
#endif
|
[LOG_CLASS_NONE] = {"none", "none", 5, -1},
|
||||||
|
[LOG_CLASS_ERROR] = {"error", " err", 31, LOG_ERR},
|
||||||
|
[LOG_CLASS_WARNING] = {"warning", "warn", 33, LOG_WARNING},
|
||||||
|
[LOG_CLASS_INFO] = {"info", "info", 97, LOG_INFO},
|
||||||
|
[LOG_CLASS_DEBUG] = {"debug", " dbg", 36, LOG_DEBUG},
|
||||||
};
|
};
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|
@ -35,20 +40,14 @@ log_init(enum log_colorize _colorize, bool _do_syslog,
|
||||||
[LOG_FACILITY_DAEMON] = LOG_DAEMON,
|
[LOG_FACILITY_DAEMON] = LOG_DAEMON,
|
||||||
};
|
};
|
||||||
|
|
||||||
static const int level_map[] = {
|
|
||||||
[LOG_CLASS_ERROR] = LOG_ERR,
|
|
||||||
[LOG_CLASS_WARNING] = LOG_WARNING,
|
|
||||||
[LOG_CLASS_INFO] = LOG_INFO,
|
|
||||||
[LOG_CLASS_DEBUG] = LOG_DEBUG,
|
|
||||||
};
|
|
||||||
|
|
||||||
colorize = _colorize == LOG_COLORIZE_NEVER ? false : _colorize == LOG_COLORIZE_ALWAYS ? true : isatty(STDERR_FILENO);
|
colorize = _colorize == LOG_COLORIZE_NEVER ? false : _colorize == LOG_COLORIZE_ALWAYS ? true : isatty(STDERR_FILENO);
|
||||||
do_syslog = _do_syslog;
|
do_syslog = _do_syslog;
|
||||||
log_level = _log_level;
|
log_level = _log_level;
|
||||||
|
|
||||||
if (do_syslog) {
|
int slvl = log_level_map[_log_level].syslog_equivalent;
|
||||||
|
if (do_syslog && slvl != -1) {
|
||||||
openlog(NULL, /*LOG_PID*/0, facility_map[syslog_facility]);
|
openlog(NULL, /*LOG_PID*/0, facility_map[syslog_facility]);
|
||||||
setlogmask(LOG_UPTO(level_map[_log_level]));
|
setlogmask(LOG_UPTO(slvl));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -63,34 +62,31 @@ static void
|
||||||
_log(enum log_class log_class, const char *module, const char *file, int lineno,
|
_log(enum log_class log_class, const char *module, const char *file, int lineno,
|
||||||
const char *fmt, int sys_errno, va_list va)
|
const char *fmt, int sys_errno, va_list va)
|
||||||
{
|
{
|
||||||
|
xassert(log_class > LOG_CLASS_NONE);
|
||||||
|
xassert(log_class < ALEN(log_level_map));
|
||||||
|
|
||||||
if (log_class > log_level)
|
if (log_class > log_level)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
const char *class = "abcd";
|
const char *prefix = log_level_map[log_class].log_prefix;
|
||||||
int class_clr = 0;
|
unsigned int class_clr = log_level_map[log_class].color;
|
||||||
switch (log_class) {
|
|
||||||
case LOG_CLASS_ERROR: class = " err"; class_clr = 31; break;
|
|
||||||
case LOG_CLASS_WARNING: class = "warn"; class_clr = 33; break;
|
|
||||||
case LOG_CLASS_INFO: class = "info"; class_clr = 97; break;
|
|
||||||
case LOG_CLASS_DEBUG: class = " dbg"; class_clr = 36; break;
|
|
||||||
}
|
|
||||||
|
|
||||||
char clr[16];
|
char clr[16];
|
||||||
snprintf(clr, sizeof(clr), "\033[%dm", class_clr);
|
xsnprintf(clr, sizeof(clr), "\033[%um", class_clr);
|
||||||
fprintf(stderr, "%s%s%s: ", colorize ? clr : "", class, colorize ? "\033[0m" : "");
|
fprintf(stderr, "%s%s%s: ", colorize ? clr : "", prefix, colorize ? "\033[0m" : "");
|
||||||
|
|
||||||
if (colorize)
|
if (colorize)
|
||||||
fprintf(stderr, "\033[2m");
|
fputs("\033[2m", stderr);
|
||||||
fprintf(stderr, "%s:%d: ", file, lineno);
|
fprintf(stderr, "%s:%d: ", file, lineno);
|
||||||
if (colorize)
|
if (colorize)
|
||||||
fprintf(stderr, "\033[0m");
|
fputs("\033[0m", stderr);
|
||||||
|
|
||||||
vfprintf(stderr, fmt, va);
|
vfprintf(stderr, fmt, va);
|
||||||
|
|
||||||
if (sys_errno != 0)
|
if (sys_errno != 0)
|
||||||
fprintf(stderr, ": %s", strerror(sys_errno));
|
fprintf(stderr, ": %s", strerror(sys_errno));
|
||||||
|
|
||||||
fprintf(stderr, "\n");
|
fputc('\n', stderr);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
|
@ -98,19 +94,14 @@ _sys_log(enum log_class log_class, const char *module,
|
||||||
const char UNUSED *file, int UNUSED lineno,
|
const char UNUSED *file, int UNUSED lineno,
|
||||||
const char *fmt, int sys_errno, va_list va)
|
const char *fmt, int sys_errno, va_list va)
|
||||||
{
|
{
|
||||||
|
xassert(log_class > LOG_CLASS_NONE);
|
||||||
|
xassert(log_class < ALEN(log_level_map));
|
||||||
|
|
||||||
if (!do_syslog)
|
if (!do_syslog)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
/* Map our log level to syslog's level */
|
/* Map our log level to syslog's level */
|
||||||
int level = -1;
|
int level = log_level_map[log_class].syslog_equivalent;
|
||||||
switch (log_class) {
|
|
||||||
case LOG_CLASS_ERROR: level = LOG_ERR; break;
|
|
||||||
case LOG_CLASS_WARNING: level = LOG_WARNING; break;
|
|
||||||
case LOG_CLASS_INFO: level = LOG_INFO; break;
|
|
||||||
case LOG_CLASS_DEBUG: level = LOG_DEBUG; break;
|
|
||||||
}
|
|
||||||
|
|
||||||
xassert(level != -1);
|
|
||||||
|
|
||||||
char msg[4096];
|
char msg[4096];
|
||||||
int n = vsnprintf(msg, sizeof(msg), fmt, va);
|
int n = vsnprintf(msg, sizeof(msg), fmt, va);
|
||||||
|
|
@ -185,14 +176,25 @@ log_errno_provided(enum log_class log_class, const char *module,
|
||||||
va_end(va);
|
va_end(va);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static size_t
|
||||||
|
map_len(void)
|
||||||
|
{
|
||||||
|
size_t len = ALEN(log_level_map);
|
||||||
|
#ifndef _DEBUG
|
||||||
|
/* Exclude "debug" entry for non-debug builds */
|
||||||
|
len--;
|
||||||
|
#endif
|
||||||
|
return len;
|
||||||
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
log_level_from_string(const char *str)
|
log_level_from_string(const char *str)
|
||||||
{
|
{
|
||||||
if (unlikely(str[0] == '\0'))
|
if (unlikely(str[0] == '\0'))
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
for (int i = 0, n = ALEN(log_level_map); i < n; i++)
|
for (int i = 0, n = map_len(); i < n; i++)
|
||||||
if (strcmp(str, log_level_map[i]) == 0)
|
if (strcmp(str, log_level_map[i].name) == 0)
|
||||||
return i;
|
return i;
|
||||||
|
|
||||||
return -1;
|
return -1;
|
||||||
|
|
@ -205,8 +207,8 @@ log_level_string_hint(void)
|
||||||
if (buf[0] != '\0')
|
if (buf[0] != '\0')
|
||||||
return buf;
|
return buf;
|
||||||
|
|
||||||
for (size_t i = 0, pos = 0, n = ALEN(log_level_map); i < n; i++) {
|
for (size_t i = 0, pos = 0, n = map_len(); i < n; i++) {
|
||||||
const char *entry = log_level_map[i];
|
const char *entry = log_level_map[i].name;
|
||||||
const char *delim = (i + 1 < n) ? ", " : "";
|
const char *delim = (i + 1 < n) ? ", " : "";
|
||||||
pos += xsnprintf(buf + pos, sizeof(buf) - pos, "'%s'%s", entry, delim);
|
pos += xsnprintf(buf + pos, sizeof(buf) - pos, "'%s'%s", entry, delim);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
9
log.h
9
log.h
|
|
@ -5,7 +5,14 @@
|
||||||
|
|
||||||
enum log_colorize { LOG_COLORIZE_NEVER, LOG_COLORIZE_ALWAYS, LOG_COLORIZE_AUTO };
|
enum log_colorize { LOG_COLORIZE_NEVER, LOG_COLORIZE_ALWAYS, LOG_COLORIZE_AUTO };
|
||||||
enum log_facility { LOG_FACILITY_USER, LOG_FACILITY_DAEMON };
|
enum log_facility { LOG_FACILITY_USER, LOG_FACILITY_DAEMON };
|
||||||
enum log_class { LOG_CLASS_ERROR, LOG_CLASS_WARNING, LOG_CLASS_INFO, LOG_CLASS_DEBUG };
|
|
||||||
|
enum log_class {
|
||||||
|
LOG_CLASS_NONE,
|
||||||
|
LOG_CLASS_ERROR,
|
||||||
|
LOG_CLASS_WARNING,
|
||||||
|
LOG_CLASS_INFO,
|
||||||
|
LOG_CLASS_DEBUG
|
||||||
|
};
|
||||||
|
|
||||||
void log_init(enum log_colorize colorize, bool do_syslog,
|
void log_init(enum log_colorize colorize, bool do_syslog,
|
||||||
enum log_facility syslog_facility, enum log_class log_level);
|
enum log_facility syslog_facility, enum log_class log_level);
|
||||||
|
|
|
||||||
49
main.c
49
main.c
|
|
@ -61,27 +61,27 @@ 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"
|
||||||
" -C,--check-config verify configuration, exit with 0 if ok, otherwise exit with 1\n"
|
" -C,--check-config verify configuration, exit with 0 if ok, otherwise exit with 1\n"
|
||||||
" -o,--override=[section.]key=value override configuration option\n"
|
" -o,--override=[section.]key=value override configuration option\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 (%s)\n"
|
" -t,--term=TERM value to set the environment variable TERM to (%s)\n"
|
||||||
" -T,--title=TITLE initial window title (foot)\n"
|
" -T,--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"
|
||||||
" -m,--maximized start in maximized mode\n"
|
" -m,--maximized start in maximized mode\n"
|
||||||
" -F,--fullscreen start in fullscreen mode\n"
|
" -F,--fullscreen start in fullscreen mode\n"
|
||||||
" -L,--login-shell start shell as a login shell\n"
|
" -L,--login-shell start shell as a login shell\n"
|
||||||
" -D,--working-directory=DIR directory to start in (CWD)\n"
|
" -D,--working-directory=DIR directory to start in (CWD)\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"
|
||||||
" -H,--hold remain open after child process exits\n"
|
" -H,--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"
|
||||||
" -d,--log-level={info|warning|error} log level (info)\n"
|
" -d,--log-level={info|warning|error|none} log level (info)\n"
|
||||||
" -l,--log-colorize=[{never|always|auto}] enable/disable colorization of log output on stderr\n"
|
" -l,--log-colorize=[{never|always|auto}] enable/disable colorization of log output on stderr\n"
|
||||||
" -s,--log-no-syslog disable syslog logging (only applicable in server mode)\n"
|
" -s,--log-no-syslog disable syslog logging (only applicable in server mode)\n"
|
||||||
" -v,--version show the version number and quit\n",
|
" -v,--version show the version number and quit\n",
|
||||||
prog_name, prog_name, DEFAULT_TERM);
|
prog_name, prog_name, DEFAULT_TERM);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -383,11 +383,14 @@ 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_level);
|
as_server ? LOG_FACILITY_DAEMON : LOG_FACILITY_USER, log_level);
|
||||||
|
|
||||||
_Static_assert(LOG_CLASS_ERROR + 1 == FCFT_LOG_CLASS_ERROR,
|
_Static_assert((int)LOG_CLASS_ERROR == (int)FCFT_LOG_CLASS_ERROR,
|
||||||
"fcft log level enum offset");
|
"fcft log level enum offset");
|
||||||
_Static_assert((int)LOG_COLORIZE_ALWAYS == (int)FCFT_LOG_COLORIZE_ALWAYS,
|
_Static_assert((int)LOG_COLORIZE_ALWAYS == (int)FCFT_LOG_COLORIZE_ALWAYS,
|
||||||
"fcft colorize enum mismatch");
|
"fcft colorize enum mismatch");
|
||||||
fcft_log_init((enum fcft_log_colorize)log_colorize, as_server && log_syslog, log_level + 1);
|
fcft_log_init(
|
||||||
|
(enum fcft_log_colorize)log_colorize,
|
||||||
|
as_server && log_syslog,
|
||||||
|
(enum fcft_log_class)log_level);
|
||||||
|
|
||||||
argc -= optind;
|
argc -= optind;
|
||||||
argv += optind;
|
argv += optind;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue