This is the mail archive of the
cluster-cvs@sourceware.org
mailing list for the cluster.
cluster: master - groupd: new logging stuff
- From: David Teigland <teigland at fedoraproject dot org>
- To: cluster-cvs-relay at redhat dot com
- Date: Wed, 19 Nov 2008 21:01:34 +0000 (UTC)
- Subject: cluster: master - groupd: new logging stuff
Gitweb: http://git.fedorahosted.org/git/cluster.git?p=cluster.git;a=commitdiff;h=cabdee28f4405462e5957c499b8f89b6b427a755
Commit: cabdee28f4405462e5957c499b8f89b6b427a755
Parent: d8c8365bc125cce66742d6c07e7f48b97589059a
Author: David Teigland <teigland@redhat.com>
AuthorDate: Wed Nov 19 14:53:23 2008 -0600
Committer: David Teigland <teigland@redhat.com>
CommitterDate: Wed Nov 19 15:01:00 2008 -0600
groupd: new logging stuff
Changes per recent discussion on cluster-devel mailing list.
Signed-off-by: David Teigland <teigland@redhat.com>
---
group/daemon/Makefile | 4 +-
group/daemon/gd_internal.h | 33 +++++----
group/daemon/logging.c | 184 ++++++++------------------------------------
group/daemon/main.c | 22 +++---
4 files changed, 65 insertions(+), 178 deletions(-)
diff --git a/group/daemon/Makefile b/group/daemon/Makefile
index d5dad51..7ab12bf 100644
--- a/group/daemon/Makefile
+++ b/group/daemon/Makefile
@@ -17,13 +17,13 @@ OBJS= app.o \
main.o \
logging.o
-CFLAGS += -I${ccsincdir} -I${cmanincdir} -I${corosyncincdir}
+CFLAGS += -I${ccsincdir} -I${cmanincdir} -I${logtincdir} -I${corosyncincdir}
CFLAGS += -I$(S) -I$(S)/../include/ -I$(S)/../lib/
CFLAGS += -I${incdir}
LDFLAGS += -L${ccslibdir} -lccs
LDFLAGS += -L${cmanlibdir} -lcman
-LDFLAGS += -L${corosynclibdir} -lcpg -llogsys -lpthread
+LDFLAGS += -L${corosynclibdir} -lcpg -llogthread -lpthread
LDFLAGS += -L${libdir}
${TARGET}: ${OBJS}
diff --git a/group/daemon/gd_internal.h b/group/daemon/gd_internal.h
index 3741f65..cda11cc 100644
--- a/group/daemon/gd_internal.h
+++ b/group/daemon/gd_internal.h
@@ -22,7 +22,7 @@
#include <sys/stat.h>
#include <sys/wait.h>
#include <corosync/cpg.h>
-#include <corosync/engine/logsys.h>
+#include <liblogthread.h>
#include "list.h"
#include "linux_endian.h"
@@ -56,51 +56,56 @@ extern int group_mode;
#define DEFAULT_GROUPD_COMPAT 2
#define DEFAULT_GROUPD_WAIT 5
#define DEFAULT_GROUPD_MODE_DELAY 2
-#define DEFAULT_DEBUG_LOGSYS 0
+#define DEFAULT_DEBUG_LOGFILE 0
extern int optd_groupd_compat;
extern int optd_groupd_wait;
extern int optd_groupd_mode_delay;
-extern int optd_debug_logsys;
+extern int optd_debug_logfile;
extern int cfgd_groupd_compat;
extern int cfgd_groupd_wait;
extern int cfgd_groupd_mode_delay;
-extern int cfgd_debug_logsys;
+extern int cfgd_debug_logfile;
void daemon_dump_save(void);
#define log_debug(fmt, args...) \
do { \
- snprintf(daemon_debug_buf, 255, "%ld " fmt "\n", time(NULL), ##args); \
+ snprintf(daemon_debug_buf, 255, fmt "\n", ##args); \
daemon_dump_save(); \
+ logt_print(LOG_DEBUG, "%s", daemon_debug_buf); \
if (daemon_debug_opt) \
fprintf(stderr, "%s", daemon_debug_buf); \
- if (cfgd_debug_logsys) \
- log_printf(LOG_DEBUG, "%s", daemon_debug_buf); \
} while (0)
#define log_group(g, fmt, args...) \
do { \
- snprintf(daemon_debug_buf, 255, "%ld %d:%s " fmt "\n", time(NULL), \
+ snprintf(daemon_debug_buf, 255, "%d:%s " fmt "\n", \
(g)->level, (g)->name, ##args); \
daemon_dump_save(); \
+ logt_print(LOG_DEBUG, "%s", daemon_debug_buf); \
if (daemon_debug_opt) \
fprintf(stderr, "%s", daemon_debug_buf); \
- if (cfgd_debug_logsys) \
- log_printf(LOG_DEBUG, "%s", daemon_debug_buf); \
} while (0)
#define log_print(fmt, args...) \
do { \
- log_debug(fmt, ##args); \
- log_printf(LOG_ERR, fmt, ##args); \
+ snprintf(daemon_debug_buf, 255, fmt "\n", ##args); \
+ daemon_dump_save(); \
+ logt_print(LOG_ERR, "%s", daemon_debug_buf); \
+ if (daemon_debug_opt) \
+ fprintf(stderr, "%s", daemon_debug_buf); \
} while (0)
#define log_error(g, fmt, args...) \
do { \
- log_group(g, fmt, ##args); \
- log_printf(LOG_ERR, fmt, ##args); \
+ snprintf(daemon_debug_buf, 255, "%d:%s " fmt "\n", \
+ (g)->level, (g)->name, ##args); \
+ daemon_dump_save(); \
+ logt_print(LOG_ERR, "%s", daemon_debug_buf); \
+ if (daemon_debug_opt) \
+ fprintf(stderr, "%s", daemon_debug_buf); \
} while (0)
#define ASSERT(x) \
diff --git a/group/daemon/logging.c b/group/daemon/logging.c
index 7b3e349..4e52c09 100644
--- a/group/daemon/logging.c
+++ b/group/daemon/logging.c
@@ -1,170 +1,52 @@
#include "gd_internal.h"
+#include "ccs.h"
-#define DAEMON_NAME "groupd"
-
-/* default: errors go to syslog (/var/log/messages) and <daemon>.log
- logging/debug=on: errors continue going to syslog (/var/log/messages)
- and <daemon>.log, debug messages are added to <daemon>.log. */
-
-#define DEFAULT_MODE LOG_MODE_OUTPUT_SYSLOG_THREADED | \
- LOG_MODE_OUTPUT_FILE | \
- LOG_MODE_NOSUBSYS | \
- LOG_MODE_FILTER_DEBUG_FROM_SYSLOG
-#define DEFAULT_FACILITY SYSLOGFACILITY /* cluster config setting */
-#define DEFAULT_PRIORITY SYSLOGLEVEL /* cluster config setting */
-#define DEFAULT_FILE LOGDIR "/" DAEMON_NAME ".log"
-
-#define DAEMON_LEVEL_PATH "/cluster/logging/logger_subsys[@subsys=\"GROUPD\"]/@syslog_level"
-#define DAEMON_DEBUG_PATH "/cluster/logging/logger_subsys[@subsys=\"GROUPD\"]/@debug"
-
-/* Read cluster.conf settings and convert them into logsys values.
- If no cluster.conf setting exists, the default that was used in
- logsys_init() is used.
-
- mode from
- "/cluster/logging/@to_stderr"
- "/cluster/logging/@to_syslog"
- "/cluster/logging/@to_file"
+extern int ccs_handle;
- facility from
- "/cluster/logging/@syslog_facility"
-
- priority from
- "/cluster/logging/logger_subsys[@subsys=\"prog_name\"]/@syslog_level"
-
- file from
- "/cluster/logging/@logfile"
-
- debug from
- "/cluster/logging/@debug"
- "/cluster/logging/logger_subsys[@subsys=\"prog_name\"]/@debug"
-*/
+#define DAEMON_NAME "groupd"
+#define DEFAULT_LOG_MODE LOG_MODE_OUTPUT_FILE|LOG_MODE_OUTPUT_SYSLOG
+#define DEFAULT_SYSLOG_FACILITY SYSLOGFACILITY
+#define DEFAULT_SYSLOG_PRIORITY SYSLOGLEVEL
+#define DEFAULT_LOGFILE_PRIORITY LOG_INFO /* ? */
+#define DEFAULT_LOGFILE LOGDIR "/" DAEMON_NAME ".log"
+
+static int log_mode;
+static int syslog_facility;
+static int syslog_priority;
+static int logfile_priority;
+static char logfile[PATH_MAX];
-static int read_ccs_logging(int *mode, int *facility, int *priority, char *file)
+void init_logging(void)
{
- char name[PATH_MAX];
- int val, y, n;
- int m = 0, f = 0, p = 0;
-
- /*
- * mode
- */
-
- m = DEFAULT_MODE;
-
- read_ccs_yesno("/cluster/logging/@to_stderr", &y, &n);
- if (y)
- m |= LOG_MODE_OUTPUT_STDERR;
- if (n)
- m &= ~LOG_MODE_OUTPUT_STDERR;
-
- read_ccs_yesno("/cluster/logging/@to_syslog", &y, &n);
- if (y)
- m |= LOG_MODE_OUTPUT_SYSLOG_THREADED;
- if (n)
- m &= ~LOG_MODE_OUTPUT_SYSLOG_THREADED;
-
- read_ccs_yesno("/cluster/logging/@to_file", &y, &n);
- if (y)
- m |= LOG_MODE_OUTPUT_FILE;
- if (n)
- m &= ~LOG_MODE_OUTPUT_FILE;
-
- *mode = m;
-
- /*
- * facility
- */
-
- f = DEFAULT_FACILITY;
-
- memset(name, 0, sizeof(name));
- read_ccs_name("/cluster/logging/@syslog_facility", name);
-
- if (name[0]) {
- val = logsys_facility_id_get(name);
- if (val >= 0)
- f = val;
- }
+ log_mode = DEFAULT_LOG_MODE;
+ syslog_facility = DEFAULT_SYSLOG_FACILITY;
+ syslog_priority = DEFAULT_SYSLOG_PRIORITY;
+ logfile_priority = DEFAULT_LOGFILE_PRIORITY;
+ strcpy(logfile, DEFAULT_LOGFILE);
- *facility = f;
+ /* logfile_priority is the only one of these options that
+ can be controlled from command line or environment variable */
- /*
- * priority
- */
+ if (cfgd_debug_logfile)
+ logfile_priority = LOG_DEBUG;
- p = DEFAULT_PRIORITY;
-
- memset(name, 0, sizeof(name));
- read_ccs_name(DAEMON_LEVEL_PATH, name);
-
- if (name[0]) {
- val = logsys_priority_id_get(name);
- if (val >= 0)
- p = val;
- }
-
- *priority = p;
-
- /*
- * file
- */
-
- strcpy(file, DEFAULT_FILE);
-
- memset(name, 0, sizeof(name));
- read_ccs_name("/cluster/logging/@logfile", name);
-
- if (name[0])
- strcpy(file, name);
-
- /*
- * debug
- */
-
- if (optd_debug_logsys)
- return 0;
-
- memset(name, 0, sizeof(name));
- read_ccs_name("/cluster/logging/@debug", name);
-
- if (!strcmp(name, "on"))
- cfgd_debug_logsys = 1;
-
- memset(name, 0, sizeof(name));
- read_ccs_name(DAEMON_DEBUG_PATH, name);
-
- if (!strcmp(name, "on"))
- cfgd_debug_logsys = 1;
- else if (!strcmp(name, "off"))
- cfgd_debug_logsys = 0;
-
- return 0;
-}
-
-/* initial settings until we can read cluster.conf logging settings from ccs */
-
-void init_logging(void)
-{
- logsys_init(DAEMON_NAME, DEFAULT_MODE, DEFAULT_FACILITY,
- DEFAULT_PRIORITY, DEFAULT_FILE);
+ logt_init(DAEMON_NAME, log_mode, syslog_facility, syslog_priority,
+ logfile_priority, logfile);
}
-/* this function is also called when we get a cman config-update event */
-
void setup_logging(void)
{
- int mode, facility, priority;
- char file[PATH_MAX];
-
- memset(file, 0, PATH_MAX);
+ ccs_read_logging(ccs_handle, DAEMON_NAME,
+ &cfgd_debug_logfile, &log_mode,
+ &syslog_facility, &syslog_priority,
+ &logfile_priority, logfile);
- read_ccs_logging(&mode, &facility, &priority, file);
- logsys_conf(DAEMON_NAME, mode, facility, priority, file);
+ logt_conf(DAEMON_NAME, log_mode, syslog_facility, syslog_priority,
+ logfile_priority, logfile);
}
void close_logging(void)
{
- logsys_exit();
+ logt_exit();
}
diff --git a/group/daemon/main.c b/group/daemon/main.c
index 3faac73..ce8e75b 100644
--- a/group/daemon/main.c
+++ b/group/daemon/main.c
@@ -15,7 +15,7 @@ static int client_size = 0;
static struct client *client = NULL;
static struct pollfd *pollfd = NULL;
static char last_action[16];
-static int ccs_handle;
+int ccs_handle;
struct client {
int fd;
@@ -885,8 +885,8 @@ static void print_usage(void)
printf("\n");
printf("Options:\n");
printf("\n");
- printf(" -D Enable debugging code and don't fork\n");
- printf(" -L <num> Enable (1) or disable (0) debugging to logsys (default %d)\n", DEFAULT_DEBUG_LOGSYS);
+ printf(" -D Enable debugging to stderr and don't fork\n");
+ printf(" -L Enable debugging to log file\n");
printf(" -g <num> group compatibility mode, 0 off, 1 on, 2 detect\n");
printf(" 0: use libcpg, no backward compat, best performance\n");
printf(" 1: use libgroup for compat with cluster2/rhel5\n");
@@ -903,7 +903,7 @@ static void print_usage(void)
printf(" -V Print program version information, then exit\n");
}
-#define OPTION_STRING "L:Dg:w:d:hVv"
+#define OPTION_STRING "LDg:w:d:hVv"
static void read_arguments(int argc, char **argv)
{
@@ -920,8 +920,8 @@ static void read_arguments(int argc, char **argv)
break;
case 'L':
- optd_debug_logsys = 1;
- cfgd_debug_logsys = atoi(optarg);
+ optd_debug_logfile = 1;
+ cfgd_debug_logfile = 1;
break;
case 'g':
@@ -972,9 +972,9 @@ static void read_arguments(int argc, char **argv)
};
}
- if (!optd_debug_logsys && getenv("GROUPD_DEBUG")) {
- optd_debug_logsys = 1;
- cfgd_debug_logsys = atoi(getenv("GROUPD_DEBUG"));
+ if (getenv("GROUPD_DEBUG")) {
+ optd_debug_logfile = 1;
+ cfgd_debug_logfile = 1;
}
}
@@ -1070,10 +1070,10 @@ int group_mode;
int optd_groupd_compat;
int optd_groupd_wait;
int optd_groupd_mode_delay;
-int optd_debug_logsys;
+int optd_debug_logfile;
int cfgd_groupd_compat = DEFAULT_GROUPD_COMPAT;
int cfgd_groupd_wait = DEFAULT_GROUPD_WAIT;
int cfgd_groupd_mode_delay = DEFAULT_GROUPD_MODE_DELAY;
-int cfgd_debug_logsys = DEFAULT_DEBUG_LOGSYS;
+int cfgd_debug_logfile = DEFAULT_DEBUG_LOGFILE;