logger: Add NetBSD -d SD for RFC5424 structured data

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
This commit is contained in:
Joachim Nilsson 2019-11-07 22:10:27 +01:00
parent 12d5536dfc
commit 31815d6143
2 changed files with 18 additions and 4 deletions

View File

@ -33,6 +33,7 @@
.Sh SYNOPSIS
.Nm
.Op Fl chinsv
.Op Fl d Ar SD
.Op Fl f Ar FILE
.Op Fl m Ar MSGID
.Op Fl p Ar PRIO
@ -60,6 +61,14 @@ if
.Fn syslog
fails to send message to
.Xr syslogd 8 .
.It Fl d Ar SD
Log this in the structured data (SD) field of an RFC5424 style log
message. See
.Fl m
for caveats. Also, please note that
.Ar sd
has to be passed as one argument and will require careful quoting when
used from the shell.
.It Fl f Ar FILE
Log file to write messages to, instead of syslog daemon.
.Nm

View File

@ -183,6 +183,7 @@ static int usage(int code)
"Write MESSAGE (or line-by-line stdin) to syslog, or file (with logrotate).\n"
"\n"
" -c Log to console (LOG_CONS) on failure\n"
" -d SD Log SD as RFC5424 style 'structured data' in message\n"
" -i Log the process ID of the logger process with each line (LOG_PID)\n"
" -m MSGID The MSGID used for the message\n"
" -n Open log file immediately (LOG_NDELAY)\n"
@ -213,16 +214,20 @@ int main(int argc, char *argv[])
int rotate = 0;
off_t size = 200 * 1024;
char *ident = NULL, *logfile = NULL;
char *msgid = NULL;
char *msgid = NULL, *sd = NULL;
char *sockpath = NULL;
char buf[512] = "";
while ((c = getopt(argc, argv, "?cf:im:np:r:st:u:v")) != EOF) {
while ((c = getopt(argc, argv, "?cd:f:im:np:r:st:u:v")) != EOF) {
switch (c) {
case 'c':
log_opts |= LOG_CONS;
break;
case 'd':
sd = optarg;
break;
case 'f':
logfile = optarg;
break;
@ -308,9 +313,9 @@ int main(int argc, char *argv[])
if (!buf[0]) {
while ((fgets(buf, sizeof(buf), stdin)))
syslogp_r(severity, &log, msgid, NULL, "%s", chomp(buf));
syslogp_r(severity, &log, msgid, sd, "%s", chomp(buf));
} else
syslogp_r(severity, &log, msgid, NULL, "%s", buf);
syslogp_r(severity, &log, msgid, sd, "%s", buf);
closelog_r(&log);