Re: Syslog and pg_options (for RPMs) - Mailing list pgsql-hackers

From ncm@zembu.com (Nathan Myers)
Subject Re: Syslog and pg_options (for RPMs)
Date
Msg-id 20010209011631.A22421@store.zembu.com
Whole thread Raw
In response to Re: Syslog and pg_options (for RPMs)  (Vince Vielhaber <vev@michvhf.com>)
List pgsql-hackers
On Thu, Feb 08, 2001 at 11:36:38PM -0500, Vince Vielhaber wrote:
> On 8 Feb 2001, Ian Lance Taylor wrote:
> >
> > Unfortunately, the license [to splogger] probably precludes
> > including it with Postgres.  Fortunately, it's only 72 lines long, and
> > would be trivial to recreate.
> 
> I missed most of this, but has anyone actually ASKED Dan for permission?

What's the point?  I've attached an independent implementation.
It recognizes tags for all seven levels.  It needs no command-line 
arguments.  Untagged messages end up logged as "LOG_NOTICE".  
Use it freely.

Nathan Myers
ncm@zembu.com

--------------
/* pglogger: stdin-to-syslog gateway for postgresql.** Copyright 2001 by Nathan Myers <ncm@nospam.cantrip.org>*
Permissionis granted to make copies for any purpose if* this copyright notice is retained unchanged.
 
*/

#include <stdio.h>
#include <stddef.h>
#include <syslog.h>
#include <string.h>

char* levels[] =
{   "", "emerg:", "alert:", "crit:", "err:",   "warning:", "notice:", "info:", "debug:" 
};

int lengths[] = 
{   0, sizeof("emerg"), sizeof("alert"), sizeof("crit"), sizeof("err"),   sizeof("warning"), sizeof("notice"),
sizeof("info"),sizeof("debug")
 
};

int priorities[] = 
{ LOG_NOTICE, LOG_EMERG, LOG_ALERT, LOG_CRIT, LOG_ERR,  LOG_WARNING, LOG_NOTICE, LOG_INFO, LOG_DEBUG
};

int main()
{   char buf[301];   int c;   char* pos = buf;   int colon = 0;

#ifndef DEBUG   openlog("postgresql", LOG_CONS, LOG_LOCAL1);
#endif   while ( (c = getchar()) != EOF) {       if (c == '\r') {         continue;       }       if (c == '\n') {
    int level = (colon ? sizeof(levels)/sizeof(*levels) : 1);           char* bol;
 
           *pos = 0;           while (--level) {               if (pos - buf >= lengths[level]                    &&
strncmp(buf,levels[level], lengths[level]) == 0) {                   break;                }           }           bol
=buf + lengths[level];           if (bol > buf && *bol == ' ') {               ++bol;           }           if (pos -
bol> 0) {
 
#ifndef DEBUG               syslog(priorities[level], "%s", bol);
#else               printf("%d/%s\n", priorities[level], bol);
#endif           }           pos = buf;           colon = 0;           continue;       }       if (c == ':') {
colon = 1;       }       if ((size_t)(pos - buf) < sizeof(buf)-1) {           *pos++ = c;       }   }   return 0;
 
}


pgsql-hackers by date:

Previous
From: Tom Lane
Date:
Subject: Re: Btree runtime recovery. Stuck spins.
Next
From: "Maurizio"
Date:
Subject: Re: 7.1 beta 3 CHANGES FOR QNX