Re: Syslog and pg_options (for RPMs)

From: ncm(at)zembu(dot)com (Nathan Myers)
To: pgsql-hackers(at)postgresql(dot)org
Subject: Re: Syslog and pg_options (for RPMs)
Date: 2001-02-09 09:16:31
Message-ID: 20010209011631.A22421@store.zembu.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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(at)zembu(dot)com

--------------
/* pglogger: stdin-to-syslog gateway for postgresql.
*
* Copyright 2001 by Nathan Myers <ncm(at)nospam(dot)cantrip(dot)org>
* Permission is 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;
}

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Maurizio 2001-02-09 14:03:23 Re: 7.1 beta 3 CHANGES FOR QNX
Previous Message Tom Lane 2001-02-09 06:30:31 Re: Btree runtime recovery. Stuck spins.