NetBSD-Users archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: Feed facility/priority to logger(1) via stdin - desirable extension or bad idea?



You wrote:

- Can what I have in mind already be solved (differently or more
elegantly) with existing tools from the base system?

[...]

Anyway, the motivation behind the idea is for the script case that
one can save calling a new logger process for each individual line
to be output.


Since a) logger(1) can read input from stdin and b) there are a limited
no. of facilities and levels, you can just start logger(1) processes for
each unique facility.level and keep them around feeding them input.

This work for you?:

```
#!/usr/bin/awk -f

BEGIN {
	LVL[0] = "emerg"
	LVL[1] = "alert"
	LVL[2] = "crit"
	LVL[3] = "err"
	LVL[4] = "warning"
	LVL[5] = "notice"
	LVL[6] = "info"
	LVL[7] = "debug"

	FAC[0] = "kern"
	FAC[1] = "user"
	FAC[2] = "mail"
	FAC[3] = "daemon"
	FAC[4] = "auth"
	FAC[5] = "syslog"
	FAC[6] = "lpr"
	FAC[7] = "news"
	FAC[8] = "uucp"
	FAC[9] = "cron"
	FAC[10] = "authpriv"
	FAC[11] = "ftp"
	FAC[12] = "ntp"
	FAC[13] = "security"
	FAC[14] = "console"

	FAC[16] = "local0"
	FAC[17] = "local1"
	FAC[18] = "local2"
	FAC[19] = "local3"
	FAC[20] = "local4"
	FAC[21] = "local5"
	FAC[22] = "local6"
	FAC[23] = "local7"

	DEFPRIO = "user.notice"
}
function getprio(msg, start, len,	i, f, l)
{
	i = int(substr(msg, start+1, len-2))
	f = int(i / 8)		# extract facility
	l = i - (f * 8)		#    "    level
	return FAC[f] "." LVL[l]
}
function logit(prio, msg)
{
	proc = "logger -p " prio
	if (!(proc in PROCS))
		PROCS[proc] = proc
	print msg | PROCS[proc]
}
{
	s = $0
	if (match(s, "<[[:digit:]]+>")) {
		prio = getprio(s, RSTART, RLENGTH)
		s = substr(s, RSTART + RLENGTH)
	} else
		prio = DEFPRIO
	logit(prio, s)
}
END {
	for (proc in PROCS)
		close(PROCS[proc])
}
```

Input is of the form:

<134>message line...

as described in the Linux logger(1) man-page (if I've got it right).

-RVP


Home | Main Index | Thread Index | Old Index