logger: Add NetBSD -m MSGID support for logging RFC5424 style

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
This commit is contained in:
Joachim Nilsson 2019-11-07 21:41:33 +01:00
parent f2e1793cda
commit e25f835a5a
2 changed files with 20 additions and 8 deletions

View File

@ -34,6 +34,7 @@
.Nm
.Op Fl chinsv
.Op Fl f Ar FILE
.Op Fl m Ar MSGID
.Op Fl p Ar PRIO
.Op Fl r Ar SIZE:NUM
.Op Fl t Ar TAG
@ -68,6 +69,11 @@ as an alias for
.It Fl i
Log the process id of the logger process with each line
.Ql ( LOG_PID ) .
.It Fl m Ar MSGID
The MSGID used for the message. Requires RFC5424 support in
.Xr syslogd 8
for receiving the message and also for storing it properly in a log file
or sending remote in correctly formatted RFC5424 style.
.It Fl n
Open log file immediately
.Ql ( LOG_NDELAY ) .

View File

@ -184,6 +184,7 @@ static int usage(int code)
"\n"
" -c Log to console (LOG_CONS) on failure\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"
" -p PRIO Log message priority (numeric or facility.severity pair)\n"
" -t TAG Log using the specified tag (defaults to user name)\n"
@ -212,10 +213,11 @@ int main(int argc, char *argv[])
int rotate = 0;
off_t size = 200 * 1024;
char *ident = NULL, *logfile = NULL;
char *msgid = NULL;
char *sockpath = NULL;
char buf[512] = "";
while ((c = getopt(argc, argv, "?cf:inp:r:st:u:v")) != EOF) {
while ((c = getopt(argc, argv, "?cf:im:np:r:st:u:v")) != EOF) {
switch (c) {
case 'c':
log_opts |= LOG_CONS;
@ -229,6 +231,10 @@ int main(int argc, char *argv[])
log_opts |= LOG_PID;
break;
case 'm':
msgid = optarg;
break;
case 'n':
log_opts |= LOG_NDELAY;
break;
@ -302,9 +308,9 @@ int main(int argc, char *argv[])
if (!buf[0]) {
while ((fgets(buf, sizeof(buf), stdin)))
syslog_r(severity, &log, "%s", chomp(buf));
syslogp_r(severity, &log, msgid, NULL, "%s", chomp(buf));
} else
syslog_r(severity, &log, "%s", buf);
syslogp_r(severity, &log, msgid, NULL, "%s", buf);
closelog_r(&log);