Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 8d1b6de

Browse files
committed
Add pg_logger to /contrib.
1 parent e937156 commit 8d1b6de

File tree

4 files changed

+124
-0
lines changed

4 files changed

+124
-0
lines changed

contrib/README

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,10 @@ pg_dumplo -
8989
Dump large objects
9090
by Karel Zak <zakkr@zf.jcu.cz>
9191

92+
pg_logger -
93+
Stdin-to-syslog gateway for PostgreSQL
94+
by Nathan Myers <ncm@nospam.cantrip.org>
95+
9296
pgbench -
9397
TPC-B like benchmarking tool
9498
by Tatsuo Ishii <t-ishii@sra.co.jp>

contrib/pg_logger/Makefile

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#
2+
# $Header: /cvsroot/pgsql/contrib/pg_logger/Attic/Makefile,v 1.1 2001/02/11 02:18:27 momjian Exp $
3+
#
4+
5+
subdir = contrib/pg_logger
6+
top_builddir = ../..
7+
include $(top_builddir)/src/Makefile.global
8+
9+
OBJS = pg_logger.o
10+
11+
all: pg_logger
12+
13+
pg_logger: $(OBJS)
14+
$(CC) $(CFLAGS) $(LDFLAGS) $(OBJS) $(LIBS) -o $@
15+
16+
install: all installdirs
17+
$(INSTALL_PROGRAM) pg_logger$(X) $(bindir)
18+
$(INSTALL_DATA) README.pg_logger $(docdir)/contrib
19+
20+
installdirs:
21+
$(mkinstalldirs) $(bindir) $(docdir)/contrib
22+
23+
uninstall:
24+
rm -f $(bindir)/pg_logger$(X) $(docdir)/contrib/README.pg_logger
25+
26+
clean distclean maintainer-clean:
27+
rm -f pg_logger$(X) $(OBJS)
28+
29+
depend dep:
30+
$(CC) -MM -MG $(CFLAGS) *.c > depend
31+
32+
ifeq (depend,$(wildcard depend))
33+
include depend
34+
endif

contrib/pg_logger/README.pg_logger

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Stdin-to-syslog gateway for PostgreSQL

contrib/pg_logger/pg_logger.c

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
/* pg_logger: stdin-to-syslog gateway for postgresql.
2+
*
3+
* Copyright 2001 by Nathan Myers <ncm@nospam.cantrip.org>
4+
* This software is distributed free of charge with no warranty of any kind.
5+
* You have permission to make copies for any purpose, provided that (1)
6+
* this copyright notice is retained unchanged, and (2) you agree to
7+
* absolve the author of all responsibility for all consequences arising
8+
* from any use.
9+
*/
10+
11+
#include <stdio.h>
12+
#include <stddef.h>
13+
#include <syslog.h>
14+
#include <string.h>
15+
16+
struct {
17+
const char *tag;
18+
int size;
19+
int priority;
20+
} tags[] = {
21+
{ "", 0, LOG_NOTICE },
22+
{ "emerg:", sizeof("emerg"), LOG_EMERG },
23+
{ "alert:", sizeof("alert"), LOG_ALERT },
24+
{ "crit:", sizeof("crit"), LOG_CRIT },
25+
{ "err:", sizeof("err"), LOG_ERR },
26+
{ "error:", sizeof("error"), LOG_ERR },
27+
{ "warning:", sizeof("warning"), LOG_WARNING },
28+
{ "notice:", sizeof("notice"), LOG_NOTICE },
29+
{ "info:", sizeof("info"), LOG_INFO },
30+
{ "debug:", sizeof("debug"), LOG_DEBUG }
31+
};
32+
33+
int main()
34+
{
35+
char buf[301];
36+
int c;
37+
char *pos = buf;
38+
const char *colon = 0;
39+
40+
#ifndef DEBUG
41+
openlog("postgresql", LOG_CONS, LOG_LOCAL1);
42+
#endif
43+
while ( (c = getchar()) != EOF) {
44+
if (c == '\r') {
45+
continue;
46+
}
47+
if (c == '\n') {
48+
int level = sizeof(tags)/sizeof(*tags);
49+
char *bol;
50+
51+
if (colon == 0 || (size_t)(colon - buf) > sizeof("warning")) {
52+
level = 1;
53+
}
54+
*pos = 0;
55+
while (--level) {
56+
if (pos - buf >= tags[level].size
57+
&& strncmp(buf, tags[level].tag, tags[level].size) == 0) {
58+
break;
59+
}
60+
}
61+
bol = buf + tags[level].size;
62+
if (bol > buf && *bol == ' ') {
63+
++bol;
64+
}
65+
if (pos - bol > 0) {
66+
#ifndef DEBUG
67+
syslog(tags[level].priority, "%s", bol);
68+
#else
69+
printf("%d/%s\n", tags[level].priority, bol);
70+
#endif
71+
}
72+
pos = buf;
73+
colon = (char const *)0;
74+
continue;
75+
}
76+
if (c == ':' && !colon) {
77+
colon = pos;
78+
}
79+
if ((size_t)(pos - buf) < sizeof(buf)-1) {
80+
*pos++ = c;
81+
}
82+
}
83+
return 0;
84+
}
85+

0 commit comments

Comments
 (0)