add command-line option for using a different config file
[zanchey/dispense2.git] / sql-edition / syslog / pg_syslog.c
1 #include <syslog.h>
2 #include <postgres.h>
3 #include <miscadmin.h>
4 #include <libpq/libpq-be.h>
5 #include <fmgr.h>
6
7 PG_FUNCTION_INFO_V1(logmsg);
8 Datum logmsg(PG_FUNCTION_ARGS) {
9         text* arg0;
10         char* msg;
11         int len;
12
13         arg0 = PG_GETARG_TEXT_P(0);
14         len = arg0->vl_len - VARHDRSZ;
15
16         msg = (char*) palloc(len+1);
17         memcpy(msg, arg0->vl_dat, len);
18         msg[len] = '\0';
19
20         openlog("postgres", LOG_PID, LOG_LOCAL6);
21         syslog(LOG_INFO, "[%s]: %s", GetUserNameFromId(GetUserId()), msg);
22         closelog();
23
24         pfree(msg);
25
26         /* not reached */
27         PG_RETURN_VOID();
28 }

UCC git Repository :: git.ucc.asn.au