MEDIUM: log: support a new "short" format
This format is meant to be used with local file descriptors. It emits
messages only prefixed with a level, removing all the process name,
system name, date and so on. It is similar to the printk() format used
on Linux. It's suitable to be sent to a local logger compatible with
systemd's output format.
Note that the facility is still required but not used, hence it is
suggested to use "daemon" to remind that it's a local logger.
Example :
log stdout format short daemon # send everything to stdout
log stderr format short daemon notice # send important events to stderr
diff --git a/src/log.c b/src/log.c
index c8ee6a9..2aef552 100644
--- a/src/log.c
+++ b/src/log.c
@@ -67,7 +67,14 @@
.sep1 = { .area = " ", .data = 1 },
.sep2 = { .area = " - ", .data = 3 }
}
- }
+ },
+ [LOG_FORMAT_SHORT] = {
+ .name = "short",
+ .pid = {
+ .sep1 = { .area = "", .data = 0 },
+ .sep2 = { .area = " ", .data = 1 },
+ }
+ },
};
#define FD_SETS_ARE_BITFIELDS
@@ -1329,7 +1336,8 @@
const struct logsrv *logsrv = tmp;
int *plogfd = logsrv->addr.ss_family == AF_UNIX ?
&logfdunix : &logfdinet;
- char *pid_sep1 = NULL, *pid_sep2 = NULL;
+ char *pid_sep1 = "", *pid_sep2 = "";
+ char logheader_short[3];
int sent;
int maxlen;
int hdr_max = 0;
@@ -1383,6 +1391,18 @@
sd_max = sd_size; /* the SD part allowed only in RFC5424 */
break;
+ case LOG_FORMAT_SHORT:
+ /* all fields are known, skip the header generation */
+ hdr = logheader_short;
+ hdr[0] = '<';
+ hdr[1] = '0' + MAX(level, logsrv->minlvl);
+ hdr[2] = '>';
+ hdr_ptr = hdr;
+ hdr_max = 3;
+ maxlen = logsrv->maxlen - hdr_max;
+ max = MIN(size, maxlen) - 1;
+ goto send;
+
default:
continue; /* must never happen */
}