From: David Teigland <teigland@redhat.com>
To: cluster-devel.redhat.com
Subject: [Cluster-devel] logsys in cluster3
Date: Tue, 1 Jul 2008 12:21:21 -0500 [thread overview]
Message-ID: <20080701172121.GC1259@redhat.com> (raw)
In-Reply-To: <20080701163700.GB1259@redhat.com>
Here's a patch that adds a simple, function-based api to logsys, allowing
non-plugins to use it much more cleanly. It seems to mostly work with the
attached test program, which illustrates how I expect to use it in various
cluster3 programs. (What doesn't work yet is the "test 1" output
following the logsys_init() call.)
Index: logsys.c
===================================================================
--- logsys.c (revision 1568)
+++ logsys.c (working copy)
@@ -632,3 +632,32 @@
{
worker_thread_group_wait (&log_thread_group);
}
+
+int logsys_init(char *name, int mode, int facility, int priority, char *file)
+{
+ char *errstr;
+ logsys_config_mode_set(mode);
+ logsys_config_facility_set(name, facility);
+ logsys_config_file_set(&errstr, file);
+ _logsys_config_priority_set(0, priority);
+ if ((mode & LOG_MODE_BUFFER_BEFORE_CONFIG) == 0) {
+ _logsys_wthread_create();
+ }
+ return 0;
+}
+
+int logsys_conf(char *name, int mode, int facility, int priority, char *file)
+{
+ char *errstr;
+ logsys_config_mode_set(mode);
+ logsys_config_facility_set(name, facility);
+ logsys_config_file_set(&errstr, file);
+ _logsys_config_priority_set(0, priority);
+ return 0;
+}
+
+int logsys_exit(void)
+{
+ return 0;
+}
+
Index: logsys.h
===================================================================
--- logsys.h (revision 1568)
+++ logsys.h (working copy)
@@ -170,8 +170,9 @@
} \
}
+static unsigned int logsys_subsys_id __attribute__((unused)); \
+
#define LOGSYS_DECLARE_NOSUBSYS(priority) \
-static unsigned int logsys_subsys_id __attribute__((unused)); \
__attribute__ ((constructor)) static void logsys_nosubsys_init (void) \
{ \
_logsys_nosubsys_set(); \
@@ -180,7 +181,6 @@
}
#define LOGSYS_DECLARE_SUBSYS(subsys,priority) \
-static unsigned int logsys_subsys_id __attribute__((unused)); \
__attribute__ ((constructor)) static void logsys_subsys_init (void) \
{ \
logsys_subsys_id = \
@@ -293,4 +293,10 @@
_logsys_config_priority_set (logsys_subsys_id, priority); \
} while(0)
+/* simple, function-based api */
+
+int logsys_init(char *name, int mode, int facility, int priority, char *file);
+int logsys_conf(char *name, int mode, int facility, int priority, char *file);
+int logsys_exit(void);
+
#endif /* LOGSYS_H_DEFINED */
-------------- next part --------------
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "logsys.h"
#define DEFAULT_MODE LOG_MODE_OUTPUT_STDERR
#define DEFAULT_FACILITY LOG_DAEMON
#define DEFAULT_PRIORITY LOG_LEVEL_INFO
#define DEFAULT_FILE NULL
char *prog_name;
int prog_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. */
int read_ccs_logging(int *mode, int *facility, int *priority, char *file,
int *debug)
{
*mode = DEFAULT_MODE;
*facility = DEFAULT_FACILITY;
*priority = DEFAULT_PRIORITY;
if (DEFAULT_FILE)
strcpy(file, DEFAULT_FILE);
/* Read settings from ccs to override the defaults above.
(with some appropriate helper functions around ccs_get, the
following can be pretty compact)
mode from
"/cluster/logging/@to_stderr"
"/cluster/logging/@to_syslog"
"/cluster/logging/@to_file"
facility from
"/cluster/logging/@syslog_facility"
priority from
"/cluster/logging/logger_subsys[@subsys=\"prog_name\"]/@syslog_level"
file from
"/cluster/logging/@filename"
debug from
"/cluster/logging/logger_subsys[@subsys=\"prog_name\"]/@debug"
*/
*mode = LOG_MODE_OUTPUT_FILE;
*priority = LOG_LEVEL_DEBUG;
strcpy(file, "/tmp/testprog.log");
return 0;
}
/* this function will also be called when we get a cman config-update event */
void setup_logging(int *prog_debug)
{
int mode, facility, priority;
char file[1024];
/* The debug setting is special, it's used by the program
and not used to configure logsys. */
read_ccs_logging(&mode, &facility, &priority, file, prog_debug);
logsys_conf(prog_name, mode, facility, priority, file);
}
int main(int argc, char **argv)
{
prog_name = argv[0];
logsys_init(prog_name, DEFAULT_MODE, DEFAULT_FACILITY,
DEFAULT_PRIORITY, DEFAULT_FILE);
log_printf(LOG_LEVEL_ERROR, "error test 1\n");
log_printf(LOG_LEVEL_DEBUG, "debug test 1\n");
setup_logging(&prog_debug);
log_printf(LOG_LEVEL_ERROR, "error test 2\n");
log_printf(LOG_LEVEL_DEBUG, "debug test 2\n");
}
next prev parent reply other threads:[~2008-07-01 17:21 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-06-30 15:23 [Cluster-devel] logsys in cluster3 David Teigland
2008-06-30 16:38 ` Fabio M. Di Nitto
2008-06-30 17:31 ` David Teigland
2008-07-01 5:01 ` Fabio M. Di Nitto
2008-07-01 16:37 ` David Teigland
2008-07-01 17:21 ` David Teigland [this message]
2008-07-01 19:12 ` David Teigland
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20080701172121.GC1259@redhat.com \
--to=teigland@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).