bug-inetutils
[Top][All Lists]
Advanced

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

[bug-inetutils] [patch] syslogd verbose patch to include facility.priori


From: Dirk Jagdmann
Subject: [bug-inetutils] [patch] syslogd verbose patch to include facility.priority in message
Date: Sat, 16 Dec 2006 00:03:10 +0100
User-agent: Mail/News 1.5.0.5 (X11/20060727)

Hello developers,

I usually don't seperate my logs very much and prefer to log everything of a specified facility into it's own logfile. However when reading or grepping through the logs I'd like to know with which priority (and sometimes facility) a message was logged. I have made a patch to syslogd which will include the facility and priority of each message in front of the message. This mode is activated by the "-v" or "--verbose" command line option. To distinguish and detect the facility and priorities I wrapped them in curly braces.

A patch is attached to this email. You're free to include the code in new releases of the inetutils collection.

--
---> Dirk Jagdmann ^ doj / cubic
----> http://cubic.org/~doj
-----> http://llg.cubic.org
Index: syslogd/syslogd.c
===================================================================
--- syslogd.orig/syslogd.c      2006-12-15 21:18:15.000000000 +0100
+++ syslogd/syslogd.c   2006-12-15 23:51:20.000000000 +0100
@@ -258,6 +258,7 @@
 time_t  now;                    /* Time use for mark and forward supending.  */
 int force_sync;                 /* GNU/Linux behaviour to sync on every line.
                                   This off by default. Set to 1 to enable.  */
+int Verbose = 0;               /* If greater 0 print <facility.priority> in 
messages. */
 
 char *program_name;
 extern int waitdaemon (int nochdir, int noclose, int maxwait);
@@ -318,6 +319,7 @@
   -s DOMAINLIST      List of domains which should be stripped from the FQDN\n\
                      of hosts before logging their name.\n\
       --help         Display this help and exit\n\
+  -v, --verbose      Prepend messages with <facility.priority>.\n\
   -V, --version      Output version information and exit");
 
       fprintf (stdout, "\nSubmit bug reports to %s.\n", PACKAGE_BUGREPORT);
@@ -325,7 +327,7 @@
   exit (err);
 }
 
-static const char *short_options = "a:dhf:Kl:m:np:rs:VS";
+static const char *short_options = "a:dhf:Kl:m:np:rs:vVS";
 static struct option long_options[] =
 {
   { "debug", no_argument, 0, 'd' },
@@ -341,6 +343,7 @@
   { "no-unixaf", no_argument, 0, 'U' },
   { "sync", no_argument, 0, 'S' },
   { "help", no_argument, 0, '&' },
+  { "verbose", no_argument, 0, 'v' },
   { "version", no_argument, 0, 'V' },
 #if 0 /* Not sure about the long name. Maybe move into conffile even.  */
   { "", required_argument, 0, 'a' },
@@ -416,6 +419,10 @@
          StripDomains = crunch_list (StripDomains, optarg);
          break;
 
+       case 'v':
+         Verbose++;
+         break;
+
        case 'P': /* Override pidfile.  */
          PidFile = optarg;
          break;
@@ -1042,6 +1049,7 @@
   int omask;
 #endif
 
+  char msg_[MAXLINE+22];
   const char *timestamp;
 
   dbg_printf ("(logmsg): %s (%d), flags %x, from %s, msg %s\n",
@@ -1070,6 +1078,22 @@
       timestamp = msg;
       msg += 16;
       msglen -= 16;
+    }
+
+  /* prepend facility.priority */
+  if(Verbose && msg[0]!='{')
+    {
+      char *p=msg_, *tp=textpri(pri);
+      int padlen=16-strlen(tp);
+      /* print fac.pri */
+      p+=sprintf(p, "{%s}", tp);
+      /* pad to 16 chars */
+      while(padlen > 0)
+       *p++=' ', --padlen;
+      /* append message */
+      strcpy(p, msg);
+      msg=msg_;
+      msglen=strlen(msg);
     }
 
   /* Extract facility and priority level.  */
Index: syslogd/syslogd.8
===================================================================
--- syslogd.orig/syslogd.8      2006-12-15 21:17:43.000000000 +0100
+++ syslogd/syslogd.8   2006-12-15 21:18:21.000000000 +0100
@@ -46,6 +46,7 @@
 .Op Fl p Ar log_socket
 .Op Fl r
 .Op Fl s Ar domain_list
+.Op Fl v
 .Op Fl -no-klog
 .Op Fl -no-unixaf
 .Op Fl -no-forward
@@ -92,6 +93,9 @@
 .It Fl s
 A colon-seperated list of domainnames which should be stripped from
 the FQDNs of hosts when logging.
+.It \fB-v\fR, \fB--verbose\fR
+Prepend messages with the facility and priority string enclosed in curly
+braces.
 .It Fl -no-klog
 Do not listen to the kernel log device. This is only supported on
 systems which define a kernel log device, on all others this is already

reply via email to

[Prev in Thread] Current Thread [Next in Thread]