Index | Thread | Search

From:
Rafael Sadowski <rafael@sizeofvoid.org>
Subject:
relayd: 1/2: separate loglevel in warn,info,debug and add log option
To:
tech@openbsd.org
Date:
Sat, 7 Nov 2026 13:16:22 +0100

Download raw body.

Thread
  • Rafael Sadowski:

    relayd: 1/2: separate loglevel in warn,info,debug and add log option

I wasn't really happy with log.c as I wanted more control over what I
see at runtime. I'm now happy with this solution.I hope you do too.

IMO It's great for debugging/test and to control what you want to see at
runtime. The default behavior does not change, the old default "brief"
corresponds to the new default "info".

The diff is split into two parts; this is the relayd part:

relayd.conf gains "log level warn|info|debug". The old keywords
"brief" and "verbose" are still accepted but print a deprecation
warning and map to "info" and "debug".

A few points I’ve changed:

- print_hex()/print_debug() are now under DEBUG, they were unreachable
  at runtime before.
- RELAYD_OPT_VERBOSE is gone, RELAYD_OPT_LOG* renamed
- IMSG_CTL_VERBOSE is replaced by IMSG_CTL_LOGLEVEL and the new
  IMSG_CTL_LOGOPTION

Keep in mind: relayd and relayctl must be updated together.

Feedback, OK?

Rafael

commit 4f506dd9da7632239d6b97a95a48e027e24fb840
Author: Rafael Sadowski <rafael@sizeofvoid.org>
Date:   Tue Nov 3 15:35:45 2026 +0100

    relayd: separate loglevel in warn,info and debug and log option
    
    It allows the user to set the log level as it is implemented: warn, info and
    debug. It also allows us to change the log level and modify the log
    options via relayctl.
    
    Is change mark log level brief/verbose as deprecated!

diff --git a/config.c b/config.c
index 1aba9de..76c1396 100644
--- a/config.c
+++ b/config.c
@@ -47,6 +47,7 @@ config_init(struct relayd *env)
 		env->sc_conf.interval.tv_sec = CHECK_INTERVAL;
 		env->sc_conf.interval.tv_usec = 0;
 		env->sc_conf.prefork_relay = RELAY_NUMPROC;
+		env->sc_conf.loglevel = LOGLVL_DEFAULT;
 		env->sc_conf.statinterval.tv_sec = RELAY_STATINTERVAL;
 		env->sc_ps->ps_csock.cs_name = RELAYD_SOCKET;
 	}
@@ -263,6 +264,37 @@ config_getreset(struct relayd *env, struct imsg *imsg)
 	return (0);
 }
 
+void
+config_setlogoption(struct ctl_logopt *logopt, struct relayd_config *sc_conf)
+{
+	int op = logopt->opt;
+
+	/* "connection" toggles both LOG_CONN and LOG_CONN_ERR together */
+	if (op & RELAYD_OPT_LOG_CONN)
+		op |= RELAYD_OPT_LOG_CONN_ERR;
+
+	if (logopt->enable)
+		sc_conf->opts |= op;
+	else
+		sc_conf->opts &= ~op;
+}
+
+const char *
+config_getlogopt_str(int opt)
+{
+	switch (opt) {
+	case RELAYD_OPT_LOG_STATE_CHANGE:
+		return ("state-changes");
+	case RELAYD_OPT_LOG_HOST_CHECKS:
+		return ("host-checks");
+	case RELAYD_OPT_LOG_CONN:
+		return ("connection");
+	case RELAYD_OPT_LOG_CONN_ERR:
+		return ("connection-errors");
+	}
+	return ("unknown");
+}
+
 int
 config_getcfg(struct relayd *env, struct imsg *imsg)
 {
@@ -278,7 +310,7 @@ config_getcfg(struct relayd *env, struct imsg *imsg)
 		return (-1);
 	}
 
-	log_setverbose((env->sc_conf.opts & RELAYD_OPT_VERBOSE) ? 2 : 0);
+	log_setlevel(env->sc_conf.loglevel);
 
 	what = ps->ps_what[privsep_process];
 
diff --git a/control.c b/control.c
index 147c491..2ecee79 100644
--- a/control.c
+++ b/control.c
@@ -228,8 +228,9 @@ control_dispatch_imsg(int fd, short event, void *arg)
 	struct ctl_conn		*c;
 	struct imsg		 imsg;
 	struct ctl_id		 id;
+	struct ctl_logopt	 logopt;
 	int			 n;
-	int			 verb;
+	u_int8_t		 loglv;
 	struct relayd		*env = cs->cs_env;
 	struct privsep		*ps = env->sc_ps;
 
@@ -407,16 +408,47 @@ control_dispatch_imsg(int fd, short event, void *arg)
 			}
 			c->flags |= CTL_CONN_NOTIFY;
 			break;
-		case IMSG_CTL_VERBOSE:
-			if (imsg_get_data(&imsg, &verb, sizeof(verb)) == -1)
+		case IMSG_CTL_LOGLEVEL:
+			if (imsg_get_data(&imsg, &loglv, sizeof(loglv)) == -1)
 				fatalx("%s: imsg_get_data", __func__);
 
+			if (loglv > LOGLVL_DEBUG) {
+				log_warnx("%s: invalid log level", __func__);
+				break;
+			}
+
+			log_warnx("log level change from %s to %s",
+			    log_getlevel_str(log_getlevel()),
+			    log_getlevel_str(loglv));
+
 			proc_forward_imsg(env->sc_ps, &imsg, PROC_PARENT);
 			proc_forward_imsg(env->sc_ps, &imsg, PROC_HCE);
 			proc_forward_imsg(env->sc_ps, &imsg, PROC_RELAY);
+			control_imsg_forward(&imsg);
+
+			env->sc_conf.loglevel = loglv;
+			log_setlevel(loglv);
+			break;
+		case IMSG_CTL_LOGOPTION:
+			if (imsg_get_data(&imsg, &logopt, sizeof(logopt)) == -1)
+				fatalx("%s: imsg_get_data", __func__);
 
+			if (logopt.opt == 0 ||
+			    (logopt.opt & ~RELAYD_OPT_LOG_ALL)) {
+				log_warnx("%s: invalid log option", __func__);
+				break;
+			}
+
+			log_warnx("log option %s %s",
+			    config_getlogopt_str(logopt.opt),
+			    logopt.enable ? "enabled" : "disabled");
+
+			config_setlogoption(&logopt, &env->sc_conf);
+
+			proc_forward_imsg(env->sc_ps, &imsg, PROC_PARENT);
+			proc_forward_imsg(env->sc_ps, &imsg, PROC_HCE);
+			proc_forward_imsg(env->sc_ps, &imsg, PROC_RELAY);
 			control_imsg_forward(&imsg);
-			log_setverbose(verb);
 			break;
 		default:
 			log_debug("%s: error handling imsg %d",
diff --git a/hce.c b/hce.c
index b9cd490..73db037 100644
--- a/hce.c
+++ b/hce.c
@@ -197,7 +197,7 @@ hce_notify_done(struct host *host, enum host_error he)
 	struct ctl_status	 st;
 	struct timeval		 tv_now, tv_dur;
 	u_long			 duration;
-	u_int			 logopt = RELAYD_OPT_LOGHOSTCHECK;
+	u_int			 logopt = RELAYD_OPT_LOG_HOST_CHECKS;
 	struct host		*h, *hostnst;
 	int			 hostup;
 	const char		*msg;
@@ -210,7 +210,7 @@ hce_notify_done(struct host *host, enum host_error he)
 		fatalx("%s: invalid table id", __func__);
 
 	if (hostnst->flags & F_DISABLE) {
-		if (env->sc_conf.opts & RELAYD_OPT_LOGUPDATE) {
+		if (env->sc_conf.opts & RELAYD_OPT_LOG_STATE_CHANGE) {
 			log_info("host %s, check %s%s (ignoring result, "
 			    "host disabled)",
 			    host->conf.name, table_check(table->conf.check),
@@ -249,7 +249,7 @@ hce_notify_done(struct host *host, enum host_error he)
 	    sizeof(st)) == -1)
 		log_warn("%s: proc_compose", __func__);
 	if (host->up != host->last_up)
-		logopt = RELAYD_OPT_LOGUPDATE;
+		logopt = RELAYD_OPT_LOG_STATE_CHANGE;
 
 	getmonotime(&tv_now);
 	timersub(&tv_now, &host->cte.tv_start, &tv_dur);
@@ -289,8 +289,14 @@ hce_dispatch_pfe(int fd, struct privsep_proc *p, struct imsg *imsg)
 	objid_t			 id;
 	struct host		*host;
 	struct table		*table;
+	struct ctl_logopt	 logopt;
 
 	switch (imsg_get_type(imsg)) {
+	case IMSG_CTL_LOGOPTION:
+		if (imsg_get_data(imsg, &logopt, sizeof(logopt)) == -1)
+			fatalx("%s: imsg_get_data", __func__);
+		config_setlogoption(&logopt, &env->sc_conf);
+		break;
 	case IMSG_HOST_DISABLE:
 		if (imsg_get_data(imsg, &id, sizeof(id)) == -1)
 			fatalx("%s: imsg_get_data", __func__);
diff --git a/log.c b/log.c
index 6d962ed..8077826 100644
--- a/log.c
+++ b/log.c
@@ -28,6 +28,7 @@
 
 static int		 debug;
 static int		 verbose;
+static u_int8_t		 loglevel;
 static const char	*log_procname;
 
 void
@@ -37,6 +38,7 @@ log_init(int n_debug, int facility)
 
 	debug = n_debug;
 	verbose = n_debug;
+	loglevel = LOGLVL_DEFAULT;
 	log_procinit(__progname);
 
 	if (!debug)
@@ -64,6 +66,38 @@ log_getverbose(void)
 	return (verbose);
 }
 
+void
+log_setlevel(u_int8_t lv)
+{
+	loglevel = lv;
+}
+
+u_int8_t
+log_getlevel(void)
+{
+	return (loglevel);
+}
+
+const char *
+log_getlevel_str(u_int8_t l)
+{
+	switch (l) {
+	case LOGLVL_WARN:
+		return ("warn");
+	case LOGLVL_INFO:
+		return ("info");
+	case LOGLVL_DEBUG:
+		return ("debug");
+	}
+	return ("unknown");
+}
+
+int
+log_is_debug(void)
+{
+	return (log_getlevel() == LOGLVL_DEBUG);
+}
+
 void
 logit(int pri, const char *fmt, ...)
 {
@@ -139,9 +173,11 @@ log_info(const char *emsg, ...)
 {
 	va_list	 ap;
 
-	va_start(ap, emsg);
-	vlog(LOG_INFO, emsg, ap);
-	va_end(ap);
+	if (log_getlevel() >= LOGLVL_INFO) {
+		va_start(ap, emsg);
+		vlog(LOG_INFO, emsg, ap);
+		va_end(ap);
+	}
 }
 
 void
@@ -149,7 +185,7 @@ log_debug(const char *emsg, ...)
 {
 	va_list	 ap;
 
-	if (verbose) {
+	if (log_is_debug()) {
 		va_start(ap, emsg);
 		vlog(LOG_DEBUG, emsg, ap);
 		va_end(ap);
diff --git a/log.h b/log.h
index ce7cbf3..1751685 100644
--- a/log.h
+++ b/log.h
@@ -22,6 +22,16 @@
 #include <sys/types.h>
 #include <stdarg.h>
 
+#define LOGLVL_WARN	0
+#define LOGLVL_INFO	1
+#define LOGLVL_DEBUG	2
+#define LOGLVL_DEFAULT	LOGLVL_INFO
+
+void		 log_setlevel(u_int8_t);
+u_int8_t	 log_getlevel(void);
+const char	*log_getlevel_str(u_int8_t);
+int		 log_is_debug(void);
+
 void		log_init(int, int);
 void		log_procinit(const char *);
 void		log_setverbose(int);
diff --git a/parse.y b/parse.y
index fcc019e..126ce48 100644
--- a/parse.y
+++ b/parse.y
@@ -213,7 +213,7 @@ typedef struct {
 %token	<v.string>	STRING
 %token  <v.number>	NUMBER
 %type	<v.string>	context hostname interface table path
-%type	<v.number>	http_type loglevel quick
+%type	<v.number>	http_type logopt loglevel quick
 %type	<v.number>	dstmode flag forwardmode retry
 %type	<v.number>	opttls opttlsclient optproxyproto
 %type	<v.number>	redirect_proto relay_proto match pflog
@@ -436,14 +436,11 @@ main		: INTERVAL NUMBER	{
 				YYERROR;
 			}
 		}
-		| LOG loglevel		{
+		| LOG logopt		{
 			conf->sc_conf.opts |= $2;
 		}
-		| LOG LEVEL VERBOSE	{
-			conf->sc_conf.opts |= RELAYD_OPT_VERBOSE;
-		}
-		| LOG LEVEL BRIEF	{
-			conf->sc_conf.opts &= ~RELAYD_OPT_VERBOSE;
+		| LOG loglevel		{
+			conf->sc_conf.loglevel = $2;
 		}
 		| TIMEOUT timeout	{
 			bcopy(&$2, &conf->sc_conf.timeout,
@@ -496,11 +493,41 @@ path		: /* nothing */		{ $$ = NULL; }
 context		: /* nothing */		{ $$ = NULL; }
 		| CONTEXT STRING	{ $$ = $2; }
 
-loglevel	: STATE CHANGES		{ $$ = RELAYD_OPT_LOGUPDATE; }
-		| HOST CHECKS		{ $$ = RELAYD_OPT_LOGHOSTCHECK; }
-		| CONNECTION		{ $$ = (RELAYD_OPT_LOGCON |
-						RELAYD_OPT_LOGCONERR); }
-		| CONNECTION ERRORS	{ $$ = RELAYD_OPT_LOGCONERR; }
+logopt		: STATE CHANGES		{ $$ = RELAYD_OPT_LOG_STATE_CHANGE; }
+		| HOST CHECKS		{ $$ = RELAYD_OPT_LOG_HOST_CHECKS; }
+		| CONNECTION		{ $$ = (RELAYD_OPT_LOG_CONN |
+						RELAYD_OPT_LOG_CONN_ERR); }
+		| CONNECTION ERRORS	{ $$ = RELAYD_OPT_LOG_CONN_ERR; }
+		;
+
+loglevel	: LEVEL STRING		{
+			if (strcmp($2, "warn") == 0)
+				$$ = LOGLVL_WARN;
+			else if (strcmp($2, "info") == 0)
+				$$ = LOGLVL_INFO;
+			else if (strcmp($2, "debug") == 0)
+				$$ = LOGLVL_DEBUG;
+			else {
+				yyerror("unknown log level: %s", $2);
+				free($2);
+				YYERROR;
+			}
+			free($2);
+		}
+		| LEVEL VERBOSE		{
+			if (loadcfg)
+				log_warnx("%s:%d: \"log level verbose\" is "
+				    "deprecated, using \"log level debug\"",
+				    file->name, file->lineno);
+			$$ = LOGLVL_DEBUG;
+		}
+		| LEVEL BRIEF		{
+			if (loadcfg)
+				log_warnx("%s:%d: \"log level brief\" is "
+				    "deprecated, using \"log level info\"",
+				    file->name, file->lineno);
+			$$ = LOGLVL_INFO;
+		}
 		;
 
 rdr		: REDIRECT STRING	{
@@ -3227,6 +3254,7 @@ load_config(const char *filename, struct relayd *x_conf)
 
 	conf = x_conf;
 	conf->sc_conf.flags = 0;
+	conf->sc_conf.loglevel = LOGLVL_DEFAULT;
 
 	loadcfg = 1;
 	errors = 0;
@@ -3256,9 +3284,8 @@ load_config(const char *filename, struct relayd *x_conf)
 	/* Free macros and check which have not been used. */
 	for (sym = TAILQ_FIRST(&symhead); sym != NULL; sym = next) {
 		next = TAILQ_NEXT(sym, entry);
-		if ((conf->sc_conf.opts & RELAYD_OPT_VERBOSE) && !sym->used)
-			fprintf(stderr, "warning: macro '%s' not "
-			    "used\n", sym->nam);
+		if (!sym->used)
+			log_debug("warning: macro '%s' not used", sym->nam);
 		if (!sym->persist) {
 			free(sym->nam);
 			free(sym->val);
diff --git a/pfe_filter.c b/pfe_filter.c
index c02d13c..e601b45 100644
--- a/pfe_filter.c
+++ b/pfe_filter.c
@@ -213,7 +213,7 @@ sync_table(struct relayd *env, struct rdr *rdr, struct table *table)
 		cnt = kill_srcnodes(env, table);
 	free(addlist);
 
-	if (env->sc_conf.opts & RELAYD_OPT_LOGUPDATE)
+	if (env->sc_conf.opts & RELAYD_OPT_LOG_STATE_CHANGE)
 		log_info("table %s: %d added, %d deleted, "
 		    "%d changed, %d killed", io.pfrio_table.pfrt_name,
 		    io.pfrio_nadd, io.pfrio_ndel, io.pfrio_nchange, cnt);
diff --git a/proc.c b/proc.c
index 4e2aaec..acba4a9 100644
--- a/proc.c
+++ b/proc.c
@@ -595,7 +595,7 @@ proc_dispatch(int fd, short event, void *arg)
 	struct imsgbuf		*ibuf;
 	struct imsg		 imsg;
 	int			 n;
-	int			 ver;
+	u_int8_t		 loglv;
 	const char		*title;
 	struct privsep_fd	 pf;
 
@@ -652,11 +652,10 @@ proc_dispatch(int fd, short event, void *arg)
 		 * Generic message handling
 		 */
 		switch (imsg_get_type(&imsg)) {
-		case IMSG_CTL_VERBOSE:
-			if (imsg_get_data(&imsg, &ver, sizeof(ver)) == -1)
+		case IMSG_CTL_LOGLEVEL:
+			if (imsg_get_data(&imsg, &loglv, sizeof(loglv)) == -1)
 				fatalx("%s: imsg_get_data", __func__);
-
-			log_setverbose(ver);
+			log_setlevel(loglv);
 			break;
 		case IMSG_CTL_PROCFD:
 			if (p->p_id != PROC_PARENT) {
diff --git a/relay.c b/relay.c
index 1f28ccd..09aa4cb 100644
--- a/relay.c
+++ b/relay.c
@@ -308,7 +308,7 @@ relay_privinit(struct relay *rlay)
 {
 	log_debug("%s: adding relay %s", __func__, rlay->rl_conf.name);
 
-	if (log_getverbose() > 1)
+	if (log_is_debug())
 		relay_protodebug(rlay);
 
 	switch (rlay->rl_proto->type) {
@@ -732,7 +732,8 @@ relay_connected(int fd, short sig, void *arg)
 
 	/* Log destination if it was changed in a keep-alive connection */
 	if ((con->se_table != con->se_table0) &&
-	    (env->sc_conf.opts & (RELAYD_OPT_LOGCON|RELAYD_OPT_LOGCONERR))) {
+	    (env->sc_conf.opts &
+	     (RELAYD_OPT_LOG_CONN|RELAYD_OPT_LOG_CONN_ERR))) {
 		con->se_table0 = con->se_table;
 		memset(&obuf, 0, sizeof(obuf));
 		(void)print_host(&con->se_out.ss, obuf, sizeof(obuf));
@@ -1758,8 +1759,8 @@ relay_close(struct rsession *con, const char *msg, int err)
 
 	event_del(&con->se_ev);
 
-	if ((env->sc_conf.opts & (RELAYD_OPT_LOGCON|RELAYD_OPT_LOGCONERR)) &&
-	    msg != NULL) {
+	if ((env->sc_conf.opts &
+	    (RELAYD_OPT_LOG_CONN|RELAYD_OPT_LOG_CONN_ERR)) && msg != NULL) {
 		bzero(&ibuf, sizeof(ibuf));
 		bzero(&obuf, sizeof(obuf));
 		(void)print_host(&con->se_in.ss, ibuf, sizeof(ibuf));
@@ -1769,7 +1770,7 @@ relay_close(struct rsession *con, const char *msg, int err)
 			ptr = evbuffer_readln(con->se_log, NULL,
 			    EVBUFFER_EOL_CRLF);
 		}
-		if (err == 0 && (env->sc_conf.opts & RELAYD_OPT_LOGCON))
+		if (err == 0 && (env->sc_conf.opts & RELAYD_OPT_LOG_CONN))
 			log_info("relay %s, "
 			    "session %d (%d active), %s, %s -> %s:%d, "
 			    "%s%s%s", rlay->rl_conf.name, con->se_id,
@@ -1777,7 +1778,7 @@ relay_close(struct rsession *con, const char *msg, int err)
 			    tag_id2name(con->se_tag) : "0", ibuf, obuf,
 			    ntohs(con->se_out.port), msg, ptr == NULL ?
 			    "" : ",", ptr == NULL ? "" : ptr);
-		if (err == 1 && (env->sc_conf.opts & RELAYD_OPT_LOGCONERR))
+		if (err == 1 && (env->sc_conf.opts & RELAYD_OPT_LOG_CONN_ERR))
 			log_warn("relay %s, "
 			    "session %d (%d active), %s, %s -> %s:%d, "
 			    "%s%s%s", rlay->rl_conf.name, con->se_id,
@@ -1875,10 +1876,18 @@ relay_dispatch_pfe(int fd, struct privsep_proc *p, struct imsg *imsg)
 	struct host		*host;
 	struct table		*table;
 	struct ctl_status	 st;
+	struct ctl_logopt	 logopt;
 	objid_t			 id;
 	int			 cid;
 
 	switch (imsg_get_type(imsg)) {
+	case IMSG_CTL_LOGOPTION:
+		if (imsg_get_data(imsg, &logopt, sizeof(logopt)) == -1) {
+			log_warn("%s: imsg_get_data", __func__);
+			return (-1);
+		}
+		config_setlogoption(&logopt, &env->sc_conf);
+		break;
 	case IMSG_HOST_DISABLE:
 		if (imsg_get_data(imsg, &id, sizeof(id)) == -1)
 			fatalx("%s: imsg_get_data", __func__);
diff --git a/relay_udp.c b/relay_udp.c
index e16b9af..fd1e04a 100644
--- a/relay_udp.c
+++ b/relay_udp.c
@@ -465,7 +465,7 @@ relay_dns_request(struct rsession *con)
 
 	if (buf == NULL || priv == NULL || len < 1)
 		return (-1);
-	if (log_getverbose() > 1)
+	if (log_is_debug())
 		relay_dns_log(con, buf, len);
 
 	getmonotime(&con->se_tv_start);
@@ -520,7 +520,7 @@ relay_dns_result(struct rsession *con, u_int8_t *buf, size_t len)
 	if (priv == NULL)
 		fatalx("%s: response to invalid session", __func__);
 
-	if (log_getverbose() > 1)
+	if (log_is_debug())
 		relay_dns_log(con, buf, len);
 
 	/*
diff --git a/relayd.c b/relayd.c
index 1b4f177..e0c6fec 100644
--- a/relayd.c
+++ b/relayd.c
@@ -125,7 +125,7 @@ main(int argc, char *argv[])
 {
 	int			 c;
 	int			 debug = 0;
-	u_int32_t		 opts = 0;
+	u_int16_t		 opts = 0;
 	struct relayd		*env;
 	struct privsep		*ps;
 	const char		*conffile = CONF_FILE;
@@ -154,7 +154,6 @@ main(int argc, char *argv[])
 			break;
 		case 'v':
 			cli_verbose = 1;
-			opts |= RELAYD_OPT_VERBOSE;
 			break;
 		case 'P':
 			title = optarg;
@@ -195,15 +194,17 @@ main(int argc, char *argv[])
 	/* initialize the TLS session id to a random key for all relay procs */
 	arc4random_buf(env->sc_conf.tls_sid, sizeof(env->sc_conf.tls_sid));
 
+	env->sc_conf.loglevel = LOGLVL_DEFAULT;
+
 	if (parse_config(env->sc_conffile, env) == -1)
 		exit(1);
 
-	if (debug)
-		env->sc_conf.opts |= RELAYD_OPT_LOGUPDATE;
-
 	/* CLI always wins over log level form config. */
 	if (cli_verbose)
-		env->sc_conf.opts |= RELAYD_OPT_VERBOSE;
+		env->sc_conf.loglevel = LOGLVL_DEBUG;
+
+	if (debug)
+		env->sc_conf.opts |= RELAYD_OPT_LOG_STATE_CHANGE;
 
 	if (geteuid())
 		errx(1, "need root privileges");
@@ -212,7 +213,7 @@ main(int argc, char *argv[])
 		errx(1, "unknown user %s", RELAYD_USER);
 
 	log_init(debug, LOG_DAEMON);
-	log_setverbose(env->sc_conf.opts & RELAYD_OPT_VERBOSE ? 2 : 0);
+	log_setlevel(env->sc_conf.loglevel);
 
 	if (env->sc_conf.opts & RELAYD_OPT_NOACTION)
 		ps->ps_noaction = 1;
@@ -325,7 +326,9 @@ parent_configure(struct relayd *env)
 
 	/* CLI always wins over log level form config. */
 	if (cli_verbose)
-		env->sc_conf.opts |= RELAYD_OPT_VERBOSE;
+		env->sc_conf.loglevel = LOGLVL_DEBUG;
+
+	log_setlevel(env->sc_conf.loglevel);
 
 	for (id = 0; id < PROC_MAX; id++) {
 		if (id == privsep_process)
@@ -422,11 +425,29 @@ parent_dispatch_pfe(int fd, struct privsep_proc *p, struct imsg *imsg)
 	struct relayd		*env = ps->ps_env;
 	struct ctl_demote	 demote;
 	struct ctl_netroute	 crt;
+	struct ctl_logopt	 logopt;
 	u_int			 v;
+	u_int8_t		 loglv;
 	char			*str = NULL;
 	size_t			 s;
 
 	switch (imsg_get_type(imsg)) {
+	case IMSG_CTL_LOGLEVEL:
+		if (imsg_get_data(imsg, &loglv, sizeof(loglv)) == -1) {
+			log_warn("%s: imsg_get_data", __func__);
+			return (-1);
+		}
+		env->sc_conf.loglevel = loglv;
+		log_setlevel(loglv);
+		proc_forward_imsg(ps, imsg, PROC_CA);
+		break;
+	case IMSG_CTL_LOGOPTION:
+		if (imsg_get_data(imsg, &logopt, sizeof(logopt)) == -1) {
+			log_warn("%s: imsg_get_data", __func__);
+			return (-1);
+		}
+		config_setlogoption(&logopt, &env->sc_conf);
+		break;
 	case IMSG_DEMOTE:
 		if (imsg_get_data(imsg, &demote, sizeof(demote)) == -1) {
 			log_warn("%s: imsg_get_data", __func__);
diff --git a/relayd.conf.5 b/relayd.conf.5
index 377ff8f..d526d29 100644
--- a/relayd.conf.5
+++ b/relayd.conf.5
@@ -167,16 +167,28 @@ Optionally log only
 .Ic connection errors .
 .It Xo
 .Ic log level
-.Pq Ic brief Ns | Ns Ic verbose
+.Pq Ic warn Ns | Ns Ic info Ns | Ns Ic debug
 .Xc
-Set the log verbosity.
-.Ic brief
-is the default;
-.Ic verbose
-enables debug logging, equivalent to starting
+Set the log level.
+.Ic warn
+logs only warnings and errors,
+.Ic info
+also logs informational messages and is the default,
+and
+.Ic debug
+also logs debug messages, equivalent to starting
 .Xr relayd 8
 with
 .Fl v .
+The deprecated keywords
+.Ic brief
+and
+.Ic verbose
+are mapped to
+.Ic info
+and
+.Ic debug ,
+respectively.
 .It Ic prefork Ar number
 When using relays, run the specified number of processes to handle
 relayed connections.
diff --git a/relayd.h b/relayd.h
index 80466a9..8381b91 100644
--- a/relayd.h
+++ b/relayd.h
@@ -947,11 +947,17 @@ struct ctl_conn {
 };
 TAILQ_HEAD(ctl_connlist, ctl_conn);
 
+struct ctl_logopt {
+	int	opt;
+	int	enable;
+};
+
 enum imsg_type {
 	IMSG_NONE,
 	IMSG_CTL_OK,		/* answer to relayctl requests */
 	IMSG_CTL_FAIL,
-	IMSG_CTL_VERBOSE,
+	IMSG_CTL_LOGLEVEL,
+	IMSG_CTL_LOGOPTION,
 	IMSG_CTL_PROCFD,
 	IMSG_CTL_END,
 	IMSG_CTL_RDR,
@@ -1086,6 +1092,7 @@ struct relayd_config {
 	struct timeval		 statinterval;
 	u_int16_t		 prefork_relay;
 	u_int16_t		 opts;
+	u_int8_t		 loglevel;
 	u_int32_t		 flags;
 };
 
@@ -1142,12 +1149,15 @@ struct relayd {
 	int			 sc_reload;
 };
 
-#define RELAYD_OPT_VERBOSE		0x01
 #define RELAYD_OPT_NOACTION		0x04
-#define RELAYD_OPT_LOGUPDATE		0x08
-#define RELAYD_OPT_LOGHOSTCHECK		0x10
-#define RELAYD_OPT_LOGCON		0x20
-#define RELAYD_OPT_LOGCONERR		0x40
+#define RELAYD_OPT_LOG_STATE_CHANGE	0x08
+#define RELAYD_OPT_LOG_HOST_CHECKS	0x10
+#define RELAYD_OPT_LOG_CONN		0x20
+#define RELAYD_OPT_LOG_CONN_ERR		0x40
+
+#define RELAYD_OPT_LOG_ALL	(RELAYD_OPT_LOG_STATE_CHANGE | \
+    RELAYD_OPT_LOG_HOST_CHECKS | RELAYD_OPT_LOG_CONN | \
+    RELAYD_OPT_LOG_CONN_ERR)
 
 /* control.c */
 int		 control_init(struct privsep *, struct control_sock *);
@@ -1174,8 +1184,14 @@ const char	*print_time(struct timeval *, struct timeval *, char *, size_t);
 const char	*printb_flags(const u_int32_t, const char *);
 void		 getmonotime(struct timeval *);
 struct ibuf	*string2binary(const char *);
+#ifdef DEBUG
+void		 print_debug(const char *, ...)
+		__attribute__((__format__ (printf, 1, 2)));
 void		 print_hex(uint8_t *, off_t, size_t);
-void		 print_debug(const char *, ...);
+#else
+#define print_debug(...)	do { } while (0)
+#define print_hex(b, o, l)	do { } while (0)
+#endif
 
 /* pfe.c */
 void	 pfe(struct privsep *, struct privsep_proc *);
@@ -1440,6 +1456,8 @@ int			 imsg_composev_event(struct imsgev *, uint16_t,
 /* config.c */
 int	 config_init(struct relayd *);
 void	 config_purge(struct relayd *, u_int);
+void	 config_setlogoption(struct ctl_logopt *, struct relayd_config *);
+const char *config_getlogopt_str(int);
 int	 config_setreset(struct relayd *, u_int);
 int	 config_getreset(struct relayd *, struct imsg *);
 int	 config_getcfg(struct relayd *, struct imsg *);
diff --git a/util.c b/util.c
index 11d6ff0..c38a728 100644
--- a/util.c
+++ b/util.c
@@ -326,12 +326,23 @@ fail:
 	return NULL;
 }
 
+#ifdef DEBUG
+void
+print_debug(const char *emsg, ...)
+{
+	va_list	 ap;
+
+	va_start(ap, emsg);
+	vfprintf(stderr, emsg, ap);
+	va_end(ap);
+}
+
 void
 print_hex(uint8_t *buf, off_t offset, size_t length)
 {
 	unsigned int	 i;
 
-	if (log_getverbose() < 3 || !length)
+	if (!length)
 		return;
 
 	for (i = 0; i < length; i++) {
@@ -345,15 +356,4 @@ print_hex(uint8_t *buf, off_t offset, size_t length)
 	}
 	print_debug("\n");
 }
-
-void
-print_debug(const char *emsg, ...)
-{
-	va_list	 ap;
-
-	if (log_getverbose() > 2) {
-		va_start(ap, emsg);
-		vfprintf(stderr, emsg, ap);
-		va_end(ap);
-	}
-}
+#endif