Skip to content

Commit b779787

Browse files
committed
Add pri as an option
This makes it so `syslogd` always prints the priority. Signed-off-by: Gavin D. Howard <gavin@gavinhoward.com>
1 parent c1c3f25 commit b779787

3 files changed

Lines changed: 45 additions & 3 deletions

File tree

man/syslog.conf.5

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ ACTION := /path/to/file
9191
OPTION := [OPTION,]
9292
|= RFC3164
9393
|= RFC5424
94+
|= pri
9495
|= iface=IFNAME
9596
|= rotate=ROT
9697
|= ttl=1..255
@@ -204,8 +205,8 @@ specified action. The
204205
details where or what to do with the selected input. The
205206
.Em option
206207
field, which must start with the semi-colon option delimiter (';'),
207-
currently supports log formatting, log rotation, outbound interface and
208-
TTL when forwarding to a multicast group.
208+
currently supports priority, log formatting, log rotation, outbound
209+
interface and TTL when forwarding to a multicast group.
209210
.Pp
210211
The default log format is the traditional RFC3164 (included here for
211212
completeness),
@@ -225,6 +226,22 @@ it is only the default for remote targets for compatibility reasons.
225226
.Li 2003-08-24T05:14:15.000003-07:00 192.0.2.1 myproc 8710 - - Kilroy was here.
226227
.El
227228
.Pp
229+
By default,
230+
.Nm sysklogd
231+
does not print the priority of a message. However, it will if
232+
.Sy pri
233+
is added to the options. Printing the priority adds the priority in
234+
angled brackets to the message header in accordance with the RFC
235+
standard in use. Below is an example using the user-level facility and a
236+
warning severity.
237+
.Pp
238+
.Bl -tag -compact -width "RFC3164:"
239+
.It Sy RFC3164:
240+
.Li <12> Aug 24 05:14:15 192.0.2.1 myproc[8710]: Kilroy was here.
241+
.It Sy RFC5424:
242+
.Li <12>1 2003-08-24T05:14:15.000003-07:00 192.0.2.1 myproc 8710 - - Kilroy was here.
243+
.El
244+
.Pp
228245
The log rotation, which is only relevant for files, details the max
229246
.Ar SIZE:COUNT
230247
a file can reach before it is rotated, and later compressed. This
@@ -901,6 +918,20 @@ command line option,
901918
#
902919
*.*;kern.none -/var/log/messages ;rotate=100k:10
903920
.Ed
921+
.Ss Priority
922+
The first example logs user messages to the file
923+
.Pa /var/log/messages
924+
with syncing and prints the priority for each message. The second
925+
example logs syslog messages to the file
926+
.Pa /var/log/syslog
927+
without syncing and with the rotation from the above example, on top of
928+
printing the priority for each message.
929+
.Bd -literal -offset indent
930+
# Turn on priority printing for each user and syslog message.
931+
#
932+
user.* /var/log/messages ;pri
933+
syslog.* -/var/log/syslog ;rotate=100k:10,pri
934+
.Ed
904935
.Ss Logging to Remote Syslog Server
905936
These rules redirect all messages to remote hosts. The first is to
906937
.Ql finlandia ,

src/syslogd.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2311,6 +2311,7 @@ void fprintlog_write(struct filed *f, struct iovec *iov, int iovcnt, int flags)
23112311
ssize_t len = 0;
23122312
ssize_t lsent;
23132313
time_t fwd_suspend;
2314+
int start;
23142315

23152316
switch (f->f_type) {
23162317
case F_UNUSED:
@@ -2448,7 +2449,13 @@ void fprintlog_write(struct filed *f, struct iovec *iov, int iovcnt, int flags)
24482449
if (f->f_type == F_FILE)
24492450
logrotate(f);
24502451

2451-
if (writev(f->f_file, &iov[1], iovcnt - 1) < 0) {
2452+
/* This returns 1 if priority is not set, and 0 if it is.
2453+
Since the priority is in the first index (0) of the iovec,
2454+
this becomes the index of the first item in use, skipping
2455+
the priority if the option is off. */
2456+
start = ((f->f_flags & PRI) == 0);
2457+
2458+
if (writev(f->f_file, &iov[start], iovcnt - start) < 0) {
24522459
int e = errno;
24532460

24542461
/* If a named pipe is full, just ignore it for now */
@@ -3555,6 +3562,9 @@ static void cfopts(char *ptr, struct filed *f)
35553562
if (ttl <= 0 || ttl > 255)
35563563
ttl = 0;
35573564
f->f_ttl = ttl;
3565+
}
3566+
else if (cfopt(&opt, "pri")) {
3567+
f->f_flags |= PRI;
35583568
} else if (cfopt(&opt, "rotate="))
35593569
cfrot(opt, f);
35603570
else

src/syslogd.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,7 @@
191191
#define MARK 0x008 /* this message is a mark */
192192
#define RFC3164 0x010 /* format log message according to RFC 3164 */
193193
#define RFC5424 0x020 /* format log message according to RFC 5424 */
194+
#define PRI 0x040 /* always print priority */
194195

195196
/* Syslog timestamp formats. */
196197
#define BSDFMT_DATELEN 0

0 commit comments

Comments
 (0)