tags 223554 patch
thankyou

Hi,

I'm willing to implement this feature (== supply
a patch), but I'd prefer IRIX' format over RFC 3164 -
writing out to the logfiles is no transmission, and
having a variable-length field precede the date makes
the logfile a lot harder to read. The f/p code itself
is not intuitively human-readable anyway, so I think
the way IRIX handles it[1] (two characters, first one is
priority 0-7, second is facility A-T, both prepended
to the hostname, separated from it with a colon) is just fine -
you can at least immediately see the priority.

I have already prepared a patch[2] to toggle this feature with
a global commandline switch - if the distinct control
per logfile is desired, I would code that, too.

What is your opinion?


Regards,

Jan

[1]: 
http://techpubs.sgi.com/library/tpl/cgi-bin/getdoc.cgi?coll=0650&db=man&fname=/usr/share/catman/a_man/cat1/syslogd.z
 - near the bottom of the page.

[2]: Patch attached, includes manpage changes. Locally tested
for 6h now, running smoothly.

-- 
Jan C. Nordholz
<jckn At gmx net>
diff -Naur sysklogd-1.4.1/sysklogd.8 sysklogd-1.4.1_new/sysklogd.8
--- sysklogd-1.4.1/sysklogd.8   2001-03-11 20:35:51.000000000 +0100
+++ sysklogd-1.4.1_new/sysklogd.8       2005-11-27 21:09:33.000000000 +0100
@@ -104,6 +104,16 @@
 forward any remote messages it receives to forwarding hosts which have been
 defined.
 .TP
+.B "\-i "
+Make \fBsyslogd\fR include the facility and priority with each logged message.
+The priority is encoded as a one-digit number (ranging from 0 to 7; see
+.BR syslog (2)
+for a complete list), the facility as a capital character (starting
+with ``A'' for LOG_KERN - see
+.I /usr/include/sys/syslog.h
+for their order).
+These two bytes are prepended to the hostname, separated from it by a colon.
+.TP
 .BI "\-l " "hostlist"
 Specify a hostname that should be logged only with its simple hostname
 and not the fqdn.  Multiple hosts may be specified using the colon
diff -Naur sysklogd-1.4.1/syslogd.c sysklogd-1.4.1_new/syslogd.c
--- sysklogd-1.4.1/syslogd.c    2005-11-27 19:38:18.000000000 +0100
+++ sysklogd-1.4.1_new/syslogd.c        2005-11-27 21:22:38.000000000 +0100
@@ -735,6 +735,8 @@
 char   **LocalHosts = NULL;    /* these hosts are logged with their hostname */
 int    NoHops = 1;             /* Can we bounce syslog messages through an
                                   intermediate host. */
+int    IncludePriFac = 0;      /* Whether facility and priority shall be 
included
+                                  in log messages */
 
 extern int errno;
 
@@ -747,7 +749,7 @@
 void printline(const char *hname, char *msg);
 void printsys(char *msg);
 void logmsg(int pri, char *msg, const char *from, int flags);
-void fprintlog(register struct filed *f, char *from, int flags, char *msg);
+void fprintlog(register struct filed *f, char *from, int pri, int flags, char 
*msg);
 void endtty();
 void wallmsg(register struct filed *f, struct iovec *iov);
 void reapchild();
@@ -829,7 +831,7 @@
                funix[i]  = -1;
        }
 
-       while ((ch = getopt(argc, argv, "a:dhf:l:m:np:rs:v")) != EOF)
+       while ((ch = getopt(argc, argv, "a:dhif:l:m:np:rs:v")) != EOF)
                switch((char)ch) {
                case 'a':
                        if (nfunix < MAXFUNIX)
@@ -846,6 +848,9 @@
                case 'h':
                        NoHops = 0;
                        break;
+               case 'i':
+                       IncludePriFac = 1;
+                       break;
                case 'l':
                        if (LocalHosts) {
                                fprintf (stderr, "Only one -l argument 
allowed," \
@@ -1613,7 +1618,7 @@
 
                if (f->f_file >= 0) {
                        untty();
-                       fprintlog(f, (char *)from, flags, msg);
+                       fprintlog(f, (char *)from, pri, flags, msg);
                        (void) close(f->f_file);
                        f->f_file = -1;
                }
@@ -1663,13 +1668,13 @@
                         * in the future.
                         */
                        if (now > REPEATTIME(f)) {
-                               fprintlog(f, (char *)from, flags, (char *)NULL);
+                               fprintlog(f, (char *)from, pri, flags, (char 
*)NULL);
                                BACKOFF(f);
                        }
                } else {
                        /* new line, save it */
                        if (f->f_prevcount)
-                               fprintlog(f, (char *)from, 0, (char *)NULL);
+                               fprintlog(f, (char *)from, f->f_prevpri, 0, 
(char *)NULL);
                        f->f_prevpri = pri;
                        f->f_repeatcount = 0;
                        (void) strncpy(f->f_lasttime, timestamp, 15);
@@ -1678,11 +1683,11 @@
                        if (msglen < MAXSVLINE) {
                                f->f_prevlen = msglen;
                                (void) strcpy(f->f_prevline, msg);
-                               fprintlog(f, (char *)from, flags, (char *)NULL);
+                               fprintlog(f, (char *)from, pri, flags, (char 
*)NULL);
                        } else {
                                f->f_prevline[0] = 0;
                                f->f_prevlen = 0;
-                               fprintlog(f, (char *)from, flags, msg);
+                               fprintlog(f, (char *)from, pri, flags, msg);
                        }
                }
        }
@@ -1698,15 +1703,17 @@
 } /* balance parentheses for emacs */
 #endif
 
-void fprintlog(f, from, flags, msg)
+void fprintlog(f, from, pri, flags, msg)
        register struct filed *f;
        char *from;
+       int pri;
        int flags;
        char *msg;
 {
-       struct iovec iov[6];
+       struct iovec iov[7];
        register struct iovec *v = iov;
        char repbuf[80];
+       char priostring[3];
 #ifdef SYSLOG_INET
        register int l;
        char line[MAXLINE + 1];
@@ -1722,6 +1729,17 @@
        v->iov_base = " ";
        v->iov_len = 1;
        v++;
+       if (IncludePriFac == 1) {
+               priostring[0]='0' + LOG_PRI(pri);
+               priostring[1]='A' + LOG_FAC(pri);
+               priostring[2]=':';
+               v->iov_base = priostring;
+               v->iov_len = 3;
+       } else {
+               v->iov_base = "";
+               v->iov_len = 0;
+       }
+       v++;
        v->iov_base = f->f_prevhost;
        v->iov_len = strlen(v->iov_base);
        v++;
@@ -1816,7 +1834,7 @@
                else {
                        f->f_time = now;
                        (void) snprintf(line, sizeof(line), "<%d>%s\n", 
f->f_prevpri, \
-                               (char *) iov[4].iov_base);
+                               (char *) iov[5].iov_base);
                        l = strlen(line);
                        if (l > MAXLINE)
                                l = MAXLINE;
@@ -1864,7 +1882,7 @@
                if (f->f_file == -1)
                        break;
 
-               if (writev(f->f_file, iov, 6) < 0) {
+               if (writev(f->f_file, iov, 7) < 0) {
                        int e = errno;
 
                        /* If a named pipe is full, just ignore it for now
@@ -2131,7 +2149,7 @@
                        dprintf("flush %s: repeated %d times, %d sec.\n",
                            TypeNames[f->f_type], f->f_prevcount,
                            repeatinterval[f->f_repeatcount]);
-                       fprintlog(f, LocalHostName, 0, (char *)NULL);
+                       fprintlog(f, LocalHostName, f->f_prevpri, 0, (char 
*)NULL);
                        BACKOFF(f);
                }
        }
@@ -2186,7 +2204,7 @@
                f = &Files[lognum];
                /* flush any pending output */
                if (f->f_prevcount)
-                       fprintlog(f, LocalHostName, 0, (char *)NULL);
+                       fprintlog(f, LocalHostName, f->f_prevpri, 0, (char 
*)NULL);
        }
 
        Initialized = was_initialized;
@@ -2272,7 +2290,7 @@
 
                        /* flush any pending output */
                        if (f->f_prevcount)
-                               fprintlog(f, LocalHostName, 0, (char *)NULL);
+                               fprintlog(f, LocalHostName, f->f_prevpri, 0, 
(char *)NULL);
 
                        switch (f->f_type) {
                                case F_FILE:

Attachment: signature.asc
Description: Digital signature

Reply via email to