From d63a762f799b08c28190ad3ae5ab4061aa83e762 Mon Sep 17 00:00:00 2001 From: Bruce Momjian Date: Mon, 13 Nov 2000 21:35:03 +0000 Subject: [PATCH] Ok, You guys are probably tired of me, BUT, here is another one, that adds the facility to set the program name used in syslog. (this includes the other ones). One gotcha, the parser doesn't like special characters in strings. For example, i tried to use pg-test, and if failed the parse coming from the postgresql.conf file. I don't think it's a showstopper.. Larry Rosenman --- doc/src/sgml/runtime.sgml | 26 +++++++++++++++++++++++++- src/backend/utils/error/elog.c | 23 +++++++++++++++++++++-- src/backend/utils/misc/guc.c | 28 +++++++++++++++++++++++++++- 3 files changed, 73 insertions(+), 4 deletions(-) diff --git a/doc/src/sgml/runtime.sgml b/doc/src/sgml/runtime.sgml index eff4c1aa9a..01093c57e0 100644 --- a/doc/src/sgml/runtime.sgml +++ b/doc/src/sgml/runtime.sgml @@ -1,5 +1,5 @@ @@ -821,6 +821,30 @@ env PGOPTIONS='-c geqo=off' psql + + SYSLOG_FACILITY (string) + + + If the SYSLOG option is set to 1 or greater, this option determines + the syslog facility used. You may choose + from LOCAL0, LOCAL1, LOCAL2, LOCAL3, LOCAL4, LOCAL5, LOCAL6, LOCAL7. + the default is LOCAL0 + + + + + + SYSLOG_PROGID (string) + + + If the SYSLOG option is set to 1 or greater, this option determines + the program id used to identify PostgreSQL messages + in syslog log messages. The default is + postgres. + + + + TRACE_NOTIFY (boolean) diff --git a/src/backend/utils/error/elog.c b/src/backend/utils/error/elog.c index 3f80c21580..89aeacb5ff 100644 --- a/src/backend/utils/error/elog.c +++ b/src/backend/utils/error/elog.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/utils/error/elog.c,v 1.65 2000/10/30 06:48:36 ishii Exp $ + * $Header: /cvsroot/pgsql/src/backend/utils/error/elog.c,v 1.66 2000/11/13 21:35:02 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -58,6 +58,8 @@ extern CommandDest whereToSendOutput; * ... in theory anyway */ int Use_syslog = 0; +char *Syslog_facility = "LOCAL0"; +char *Syslog_progid = "postgres"; static void write_syslog(int level, const char *line); @@ -620,6 +622,7 @@ write_syslog(int level, const char *line) static bool openlog_done = false; static unsigned long seq = 0; + static int syslog_fac = LOG_LOCAL0; int len = strlen(line); if (Use_syslog == 0) @@ -627,7 +630,23 @@ write_syslog(int level, const char *line) if (!openlog_done) { - openlog("postgres", LOG_PID | LOG_NDELAY, LOG_LOCAL0); + if (strcasecmp(Syslog_facility,"LOCAL0") == 0) + syslog_fac = LOG_LOCAL0; + if (strcasecmp(Syslog_facility,"LOCAL1") == 0) + syslog_fac = LOG_LOCAL1; + if (strcasecmp(Syslog_facility,"LOCAL2") == 0) + syslog_fac = LOG_LOCAL2; + if (strcasecmp(Syslog_facility,"LOCAL3") == 0) + syslog_fac = LOG_LOCAL3; + if (strcasecmp(Syslog_facility,"LOCAL4") == 0) + syslog_fac = LOG_LOCAL4; + if (strcasecmp(Syslog_facility,"LOCAL5") == 0) + syslog_fac = LOG_LOCAL5; + if (strcasecmp(Syslog_facility,"LOCAL6") == 0) + syslog_fac = LOG_LOCAL6; + if (strcasecmp(Syslog_facility,"LOCAL7") == 0) + syslog_fac = LOG_LOCAL7; + openlog(Syslog_progid, LOG_PID | LOG_NDELAY, syslog_fac); openlog_done = true; } diff --git a/src/backend/utils/misc/guc.c b/src/backend/utils/misc/guc.c index ecdc1d1a75..88c20a2ac0 100644 --- a/src/backend/utils/misc/guc.c +++ b/src/backend/utils/misc/guc.c @@ -4,7 +4,7 @@ * Support for grand unified configuration scheme, including SET * command, configuration file, and command line options. * - * $Header: /cvsroot/pgsql/src/backend/utils/misc/guc.c,v 1.17 2000/11/13 15:18:12 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/utils/misc/guc.c,v 1.18 2000/11/13 21:35:03 momjian Exp $ * * Copyright 2000 by PostgreSQL Global Development Group * Written by Peter Eisentraut . @@ -39,6 +39,11 @@ extern bool Log_connections; extern int CheckPointTimeout; extern int XLOGbuffers; extern int XLOG_DEBUG; +#ifdef ENABLE_SYSLOG +extern char *Syslog_facility; +extern char *Syslog_progid; + bool check_facility(const char *facility); +#endif /* * Debugging options @@ -303,6 +308,12 @@ ConfigureNamesString[] = {"unix_socket_group", PGC_POSTMASTER, &Unix_socket_group, "", NULL}, +#ifdef ENABLE_SYSLOG + {"syslog_facility", PGC_SIGHUP, &Syslog_facility, + "LOCAL0", check_facility}, + {"syslog_progid", PGC_SIGHUP, &Syslog_progid, + "postgres", NULL}, +#endif {"unixsocket", PGC_POSTMASTER, &UnixSocketName, "", NULL}, @@ -813,3 +824,18 @@ ParseLongOption(const char * string, char ** name, char ** value) if (*cp == '-') *cp = '_'; } +#ifdef ENABLE_SYSLOG +bool +check_facility(const char *facility) +{ + if (strcasecmp(facility,"LOCAL0") == 0) return true; + if (strcasecmp(facility,"LOCAL1") == 0) return true; + if (strcasecmp(facility,"LOCAL2") == 0) return true; + if (strcasecmp(facility,"LOCAL3") == 0) return true; + if (strcasecmp(facility,"LOCAL4") == 0) return true; + if (strcasecmp(facility,"LOCAL5") == 0) return true; + if (strcasecmp(facility,"LOCAL6") == 0) return true; + if (strcasecmp(facility,"LOCAL7") == 0) return true; + return false; +} +#endif -- 2.40.0