Download raw body.
relayd: 2/2: separate loglevel in warn,info,debug and add log option
This is the relayctl part from the relayd log-rework.
relayctl gains a new log syntax:
"log level warn|info|debug"
and
"log enable|disable <option>"
... to change the log level and the log options (state-changes,
host-checks, connection, connection-errors) at runtime without a reload.
Examples:
# relayctl -s /var/run/relayd-dev.sock log
missing argument:
valid commands/args:
level
enable
disable
verbose
brief
# relayctl -s /var/run/relayd-dev.sock log level
missing argument:
valid commands/args:
warn
info
debug
# relayctl -s /var/run/relayd-dev.sock log enable
missing argument:
valid commands/args:
state-changes
host-checks
connection
connection-errors
# relayctl -s /var/run/relayd-dev.sock log level warn
logging request sent.
and in the logs:
Nov 7 12:40:08 fnord relayd-dev[93169]: log level change from info to warn
# relayctl -s /var/run/relayd-dev.sock log disable host-checks
logoption request sent.
and in the logs:
Nov 7 12:40:45 fnord relayd-dev[93169]: log option host-checks disabled
Feedback, OK?
commit d92f2d0ff1608b6c484a360367f95bf46022c270
Author: Rafael Sadowski <rafael@sizeofvoid.org>
Date: Tue Nov 3 22:04:43 2026 +0100
relayctl: separate loglevel in warn,info and debug and add logoption
This means that all log options can now be controlled fine granularity,
This makes it possible to switch options at runtime without reloading
the config.
diff --git a/parser.c b/parser.c
index 9c70e7c..1b591d2 100644
--- a/parser.c
+++ b/parser.c
@@ -35,6 +35,7 @@ enum token_type {
TABLEID,
RDRID,
KEYWORD,
+ LOGOPT,
PATH
};
@@ -54,6 +55,8 @@ static const struct token t_rdr_id[];
static const struct token t_table_id[];
static const struct token t_host_id[];
static const struct token t_log[];
+static const struct token t_loglevel[];
+static const struct token t_logopt_name[];
static const struct token t_load[];
static const struct token t_main[] = {
@@ -114,11 +117,29 @@ static const struct token t_host_id[] = {
};
static const struct token t_log[] = {
- {KEYWORD, "verbose", LOG_VERBOSE, NULL},
- {KEYWORD, "brief", LOG_BRIEF, NULL},
+ {KEYWORD, "level", NONE, t_loglevel},
+ {KEYWORD, "enable", LOG_OPT_ENABLE, t_logopt_name},
+ {KEYWORD, "disable", LOG_OPT_DISABLE, t_logopt_name},
+ {KEYWORD, "verbose", LOG_LV_VERBOSE, NULL},
+ {KEYWORD, "brief", LOG_LV_BRIEF, NULL},
+ {ENDTOKEN, "", NONE, NULL}
+};
+
+static const struct token t_loglevel[] = {
+ {KEYWORD, "warn", LOG_LV_WARN, NULL},
+ {KEYWORD, "info", LOG_LV_INFO, NULL},
+ {KEYWORD, "debug", LOG_LV_DEBUG, NULL},
{ENDTOKEN, "", NONE, NULL}
};
+static const struct token t_logopt_name[] = {
+ {LOGOPT, "state-changes", RELAYD_OPT_LOG_STATE_CHANGE, NULL},
+ {LOGOPT, "host-checks", RELAYD_OPT_LOG_HOST_CHECKS, NULL},
+ {LOGOPT, "connection", RELAYD_OPT_LOG_CONN, NULL},
+ {LOGOPT, "connection-errors", RELAYD_OPT_LOG_CONN_ERR, NULL},
+ {ENDTOKEN, "", NONE, NULL}
+};
+
static const struct token t_load[] = {
{PATH, "", NONE, NULL},
{ENDTOKEN, "", NONE, NULL}
@@ -224,6 +245,21 @@ match_token(const char *word, const struct token *table,
t = &table[i];
match++;
break;
+ case LOGOPT:
+ if (word != NULL && strncmp(word, table[i].keyword,
+ strlen(word)) == 0) {
+ /* Exact match wins over prefix matches. */
+ if (strcmp(word, table[i].keyword) == 0) {
+ match = 1;
+ t = &table[i];
+ res->log_opt = t->value;
+ goto done;
+ }
+ match++;
+ t = &table[i];
+ res->log_opt = t->value;
+ }
+ break;
case PATH:
if (!match && word != NULL && strlen(word) > 0) {
res->path = strdup(word);
@@ -235,6 +271,7 @@ match_token(const char *word, const struct token *table,
break;
}
}
+done:
if (match != 1) {
if (word == NULL)
@@ -271,6 +308,9 @@ show_valid_args(const struct token *table)
case HOSTID:
fprintf(stderr, " <hostid>\n");
break;
+ case LOGOPT:
+ fprintf(stderr, " %s\n", table[i].keyword);
+ break;
case PATH:
fprintf(stderr, " <path>\n");
break;
diff --git a/parser.h b/parser.h
index 95aac58..d0bdede 100644
--- a/parser.h
+++ b/parser.h
@@ -40,13 +40,19 @@ enum actions {
LOAD,
RELOAD,
MONITOR,
- LOG_VERBOSE,
- LOG_BRIEF
+ LOG_LV_WARN,
+ LOG_LV_INFO,
+ LOG_LV_DEBUG,
+ LOG_LV_VERBOSE,
+ LOG_LV_BRIEF,
+ LOG_OPT_ENABLE,
+ LOG_OPT_DISABLE,
};
struct parse_result {
struct ctl_id id;
enum actions action;
+ int log_opt;
char *path;
};
diff --git a/relayctl.8 b/relayctl.8
index dc25f7c..99641e2 100644
--- a/relayctl.8
+++ b/relayctl.8
@@ -57,10 +57,25 @@ Enable the host.
Start checking its health again.
.It Cm load Ar filename
Reload the configuration from the specified file.
-.It Cm log brief
-Disable verbose debug logging.
-.It Cm log verbose
-Enable verbose debug logging.
+.It Cm log level Cm warn | info | debug
+Set the log level.
+Changes made via
+.Cm log
+are not persisted and are lost on the next configuration reload.
+.It Cm log enable | disable Ar type
+Enable or disable a logging option, where
+.Ar type
+is one of
+.Cm state-changes ,
+.Cm host-checks ,
+.Cm connection ,
+or
+.Cm connection-errors .
+.It Cm log Cm verbose | brief
+Deprecated, equivalent to
+.Cm log level debug
+and
+.Cm log level info .
.It Cm monitor
Continuously report any changes in the host checking engine and the
.Xr pf 4
diff --git a/relayctl.c b/relayctl.c
index 790cbc0..f624600 100644
--- a/relayctl.c
+++ b/relayctl.c
@@ -39,6 +39,7 @@
#include <imsg.h>
#include "relayd.h"
+#include "log.h"
#include "parser.h"
__dead void usage(void);
@@ -51,6 +52,7 @@ char *print_table_status(int, int);
char *print_relay_status(int);
void print_statistics(struct ctl_stats [PROC_MAX_INSTANCES+1]);
void print_imsg(struct imsg *, const char *);
+u_int8_t get_loglevel(enum actions);
struct imsgname {
int type;
@@ -101,9 +103,11 @@ main(int argc, char *argv[])
struct sockaddr_un sun;
struct parse_result *res;
struct imsg imsg;
+ struct ctl_logopt lo;
int ctl_sock;
int done = 0;
- int n, relayd_log_level = 0;
+ int n;
+ u_int8_t loglevel;
int ch;
const char *sockname;
@@ -216,15 +220,31 @@ main(int argc, char *argv[])
case MONITOR:
imsg_compose(ibuf, IMSG_CTL_NOTIFY, 0, 0, -1, NULL, 0);
break;
- case LOG_VERBOSE:
- relayd_log_level = 2;
+ case LOG_LV_VERBOSE:
+ case LOG_LV_BRIEF:
+ warnx("\"log %s\" is deprecated, use \"log level %s\"",
+ res->action == LOG_LV_VERBOSE ? "verbose" : "brief",
+ res->action == LOG_LV_VERBOSE ? "debug" : "info");
/* FALLTHROUGH */
- case LOG_BRIEF:
- imsg_compose(ibuf, IMSG_CTL_VERBOSE, 0, 0, -1,
- &relayd_log_level, sizeof(relayd_log_level));
+ case LOG_LV_WARN:
+ case LOG_LV_INFO:
+ case LOG_LV_DEBUG:
+ loglevel = get_loglevel(res->action);
+ imsg_compose(ibuf, IMSG_CTL_LOGLEVEL, 0, 0, -1,
+ &loglevel, sizeof(loglevel));
printf("logging request sent.\n");
done = 1;
break;
+ case LOG_OPT_ENABLE:
+ /* FALLTHROUGH */
+ case LOG_OPT_DISABLE:
+ lo.opt = res->log_opt;
+ lo.enable = (res->action == LOG_OPT_ENABLE);
+ imsg_compose(ibuf, IMSG_CTL_LOGOPTION, 0, 0, -1,
+ &lo, sizeof(lo));
+ printf("logoption request sent.\n");
+ done = 1;
+ break;
}
if (imsgbuf_flush(ibuf) == -1)
@@ -263,8 +283,13 @@ main(int argc, char *argv[])
done = show_command_output(&imsg);
break;
case NONE:
- case LOG_VERBOSE:
- case LOG_BRIEF:
+ case LOG_LV_WARN:
+ case LOG_LV_INFO:
+ case LOG_LV_DEBUG:
+ case LOG_LV_VERBOSE:
+ case LOG_LV_BRIEF:
+ case LOG_OPT_ENABLE:
+ case LOG_OPT_DISABLE:
case RELOAD:
case LOAD:
break;
@@ -281,6 +306,23 @@ main(int argc, char *argv[])
return (error ? 1 : 0);
}
+u_int8_t
+get_loglevel(enum actions action)
+{
+ switch (action) {
+ case LOG_LV_WARN:
+ return (LOGLVL_WARN);
+ case LOG_LV_INFO:
+ case LOG_LV_BRIEF:
+ return (LOGLVL_INFO);
+ case LOG_LV_DEBUG:
+ case LOG_LV_VERBOSE:
+ return (LOGLVL_DEBUG);
+ default:
+ return (LOGLVL_DEFAULT);
+ }
+}
+
struct imsgname *
monitor_lookup(u_int8_t type)
{
relayd: 2/2: separate loglevel in warn,info,debug and add log option