changeset 1054:c1c9a2cd63cb

irccd: add level keyword to log template
author David Demelier <markand@malikania.fr>
date Sun, 20 Jun 2021 13:01:25 +0200
parents 8d6651c3e36c
children 1965c1c23454
files lib/irccd/log.c man/irccd.conf.5
diffstat 2 files changed, 25 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/lib/irccd/log.c	Sun Jun 20 12:38:05 2021 +0200
+++ b/lib/irccd/log.c	Sun Jun 20 13:01:25 2021 +0200
@@ -25,6 +25,7 @@
 
 #include "log.h"
 #include "subst.h"
+#include "util.h"
 
 #define DEFAULT_TEMPLATE "#{message}"
 
@@ -84,12 +85,19 @@
 static void (*handler)(enum level, const char *);
 static void (*finalizer)(void);
 
+static const char *levelstr[] = {
+	[LEVEL_DEBUG]   = "debug",
+	[LEVEL_INFO]    = "info",
+	[LEVEL_WARN]    = "warning"
+};
+
 static void
 wrap(enum level level, const char *fmt, va_list ap)
 {
 	char formatted[1024] = {0}, line[1024] = {0};
 	struct irc_subst_keyword kw[] = {
-		{ "message", line }
+		{ "message",    line            },
+		{ "level",      levelstr[level] }
 	};
 	struct irc_subst subst = {
 		.time = time(NULL),
@@ -99,7 +107,7 @@
 		         IRC_SUBST_SHELL |
 		         IRC_SUBST_SHELL_ATTRS,
 		.keywords = kw,
-		.keywordsz = 1
+		.keywordsz = IRC_UTIL_SIZE(kw)
 	};
 
 	vsnprintf(line, sizeof (line), fmt, ap);
--- a/man/irccd.conf.5	Sun Jun 20 12:38:05 2021 +0200
+++ b/man/irccd.conf.5	Sun Jun 20 13:01:25 2021 +0200
@@ -63,7 +63,7 @@
 are valid.
 .\" Blocks
 .Ss Blocks
-For configuration sections that are more complex, block using braces are
+For configuration sections that are more complex, blocks using braces are
 required and each directive between the enclosing block require a trailing
 semicolon.
 .Pp
@@ -87,7 +87,7 @@
 The following sections describe what is allowed in the configuration file.
 .\" logs
 .Ss logs
-This section can let you configure how irccd should log the messages.
+This section let you configure how irccd should log the messages.
 .Bl -tag
 .It Ar logs [verbose|quiet] [template string] to console
 Use the standard output and error to log content. This the default.
@@ -111,7 +111,16 @@
 .Ar template
 can be used to format the output log entries using
 .Ar string
-as template. See
+as template. This template enable shell attributes, environment variable, date
+and has the following keywords:
+.Bl -tag -width unknown
+.It Va message
+The message line.
+.It Va level
+The level of message (debug, info or warning).
+.El
+.Pp
+See
 .Xr irccd-templates 7
 for more details.
 .\" transport
@@ -293,6 +302,9 @@
 # Logs to syslog instead of console (which is the default).
 logs verbose to syslog
 
+# Logs using a specific format string (console is recommended for colors).
+logs verbose template "%H:%M @{orange}#{level}@{} #{message}"
+
 # Enable transport with default permissions.
 transport to "/tmp/irccd.sock"