changeset 1049:e76044862cce

irccd: advertise irc_log_set_template function
author David Demelier <markand@malikania.fr>
date Sun, 20 Jun 2021 10:56:12 +0200
parents 4b53eb6fff73
children 892a11180067
files lib/irccd/log.c man/libirccd-log.3
diffstat 2 files changed, 16 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/lib/irccd/log.c	Sun Jun 20 10:38:21 2021 +0200
+++ b/lib/irccd/log.c	Sun Jun 20 10:56:12 2021 +0200
@@ -26,6 +26,8 @@
 #include "log.h"
 #include "subst.h"
 
+#define DEFAULT_TEMPLATE "#{message}"
+
 enum level {
 	LEVEL_INFO,
 	LEVEL_WARN,
@@ -34,7 +36,7 @@
 
 static FILE *out, *err;
 static int verbosity;
-static char tmpl[512] = "#{message}";
+static char tmpl[512] = DEFAULT_TEMPLATE;
 
 static void
 handler_files(enum level level, const char *line)
@@ -158,7 +160,7 @@
 void
 irc_log_set_template(const char *fmt)
 {
-	strlcpy(tmpl, fmt, sizeof (tmpl));
+	strlcpy(tmpl, fmt ? fmt : DEFAULT_TEMPLATE, sizeof (tmpl));
 }
 
 void
--- a/man/libirccd-log.3	Sun Jun 20 10:38:21 2021 +0200
+++ b/man/libirccd-log.3	Sun Jun 20 10:56:12 2021 +0200
@@ -34,6 +34,8 @@
 .Ft void
 .Fn irc_log_set_verbose "int verbose"
 .Ft void
+.Fn irc_log_set_template "const char *tmpl"
+.Ft void
 .Fn irc_log_info "const char *fmt, ..."
 .Ft void
 .Fn irc_log_warn "const char *fmt, ..."
@@ -69,11 +71,20 @@
 .Pp
 The
 .Fn irc_log_set_verbose
-change the verbosity to on if
+changes the verbosity to on if
 .Fa verbose
 is greater than 0 (which is the default).
 .Pp
 The
+.Fn irc_log_set_template
+changes the format string used to log entries with the help of
+.Xr libirccd-subst 3
+routines. Passing NULL as
+.Ar tmpl
+resets the default format to
+.Dq #{message}
+.Pp
+The
 .Fn irc_log_info
 uses the
 .Xr printf 3