Initial import
[zanchey/dispense2.git] / sql-edition / syslog / pg_syslog.c
diff --git a/sql-edition/syslog/pg_syslog.c b/sql-edition/syslog/pg_syslog.c
new file mode 100644 (file)
index 0000000..1dbdc85
--- /dev/null
@@ -0,0 +1,28 @@
+#include <syslog.h>
+#include <postgres.h>
+#include <miscadmin.h>
+#include <libpq/libpq-be.h>
+#include <fmgr.h>
+
+PG_FUNCTION_INFO_V1(logmsg);
+Datum logmsg(PG_FUNCTION_ARGS) {
+       text* arg0;
+       char* msg;
+       int len;
+
+       arg0 = PG_GETARG_TEXT_P(0);
+       len = arg0->vl_len - VARHDRSZ;
+
+       msg = (char*) palloc(len+1);
+       memcpy(msg, arg0->vl_dat, len);
+       msg[len] = '\0';
+
+       openlog("postgres", LOG_PID, LOG_LOCAL6);
+       syslog(LOG_INFO, "[%s]: %s", GetUserNameFromId(GetUserId()), msg);
+       closelog();
+
+       pfree(msg);
+
+       /* not reached */
+       PG_RETURN_VOID();
+}

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