# HG changeset patch # User David Demelier # Date 1624186885 -7200 # Node ID c1c9a2cd63cb420f3c3e690dbde64e1aeb6cfbc2 # Parent 8d6651c3e36c426486accbd07f1023c9f2231be1 irccd: add level keyword to log template diff -r 8d6651c3e36c -r c1c9a2cd63cb lib/irccd/log.c --- 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); diff -r 8d6651c3e36c -r c1c9a2cd63cb man/irccd.conf.5 --- 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"