From 8ab1d3aa9fcc715eb6aee280fdf952f64ab78dbb Mon Sep 17 00:00:00 2001 From: Steven Dake Date: Wed, 2 Jul 2008 22:58:03 +0000 Subject: [PATCH] Add init/config entry points for those that dont with to use macros in logsys. git-svn-id: http://svn.fedorahosted.org/svn/corosync/trunk@1572 fd59a12c-fef9-0310-b244-a6a79926bd2f --- exec/logsys.c | 38 ++++++++++++++++++++++++++++++++++++++ exec/logsys.h | 25 +++++++++++++++++++++++-- 2 files changed, 61 insertions(+), 2 deletions(-) diff --git a/exec/logsys.c b/exec/logsys.c index eee135b5..7159de5a 100644 --- a/exec/logsys.c +++ b/exec/logsys.c @@ -636,3 +636,41 @@ void logsys_flush (void) { worker_thread_group_wait (&log_thread_group); } + +int logsys_init (char *name, int mode, int facility, int priority, char *file) +{ + char *errstr; + + logsys_subsys_id = 0; + + strncpy (logsys_loggers[0].subsys, name, + sizeof (logsys_loggers[0].subsys)); + 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; + + strncpy (logsys_loggers[0].subsys, name, + sizeof (logsys_loggers[0].subsys)); + 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); +} + +void logsys_exit (void) +{ + logsys_subsys_id = -1; + logsys_flush (); +} + diff --git a/exec/logsys.h b/exec/logsys.h index a451bbad..7bcea92c 100644 --- a/exec/logsys.h +++ b/exec/logsys.h @@ -38,6 +38,7 @@ #include #include +#include /* * MODE_OUTPUT_SYSLOG_* modes are mutually exclusive @@ -172,8 +173,9 @@ __attribute__ ((constructor)) static void logsys_system_init (void) \ } \ } +static unsigned int logsys_subsys_id __attribute__((unused)) = -1; \ + #define LOGSYS_DECLARE_NOSUBSYS(priority) \ -static unsigned int logsys_subsys_id __attribute__((unused)); \ __attribute__ ((constructor)) static void logsys_nosubsys_init (void) \ { \ _logsys_nosubsys_set(); \ @@ -182,7 +184,6 @@ __attribute__ ((constructor)) static void logsys_nosubsys_init (void) \ } #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 = \ @@ -190,6 +191,7 @@ __attribute__ ((constructor)) static void logsys_subsys_init (void) \ } #define log_printf(lvl, format, args...) do { \ + assert (logsys_subsys_id != -1); \ if ((lvl) <= logsys_loggers[logsys_subsys_id].priority) { \ _logsys_log_printf2 (__FILE__, __LINE__, lvl, \ logsys_subsys_id, (format), ##args); \ @@ -197,6 +199,7 @@ __attribute__ ((constructor)) static void logsys_subsys_init (void) \ } while(0) #define dprintf(format, args...) do { \ + assert (logsys_subsys_id != -1); \ if (LOG_LEVEL_DEBUG <= logsys_loggers[logsys_subsys_id].priority) { \ _logsys_log_printf2 (__FILE__, __LINE__, LOG_DEBUG, \ logsys_subsys_id, (format), ##args); \ @@ -204,6 +207,7 @@ __attribute__ ((constructor)) static void logsys_subsys_init (void) \ } while(0) #define ENTER_VOID() do { \ + assert (logsys_subsys_id != -1); \ if (LOG_LEVEL_DEBUG <= logsys_loggers[logsys_subsys_id].priority) { \ _logsys_trace (__FILE__, __LINE__, LOGSYS_TAG_ENTER, \ logsys_subsys_id, ">%s\n", __FUNCTION__); \ @@ -211,6 +215,7 @@ __attribute__ ((constructor)) static void logsys_subsys_init (void) \ } while(0) #define ENTER(format, args...) do { \ + assert (logsys_subsys_id != -1); \ if (LOG_LEVEL_DEBUG <= logsys_loggers[logsys_subsys_id].priority) { \ _logsys_trace (__FILE__, __LINE__, LOGSYS_TAG_ENTER, \ logsys_subsys_id, ">%s: " format, __FUNCTION__, \ @@ -219,6 +224,7 @@ __attribute__ ((constructor)) static void logsys_subsys_init (void) \ } while(0) #define LEAVE_VOID() do { \ + assert (logsys_subsys_id != -1); \ if (LOG_LEVEL_DEBUG <= logsys_loggers[logsys_subsys_id].priority) { \ _logsys_trace (__FILE__, __LINE__, LOGSYS_TAG_LEAVE, \ logsys_subsys_id, "<%s\n", __FUNCTION__); \ @@ -226,6 +232,7 @@ __attribute__ ((constructor)) static void logsys_subsys_init (void) \ } while(0) #define LEAVE(format, args...) do { \ + assert (logsys_subsys_id != -1); \ if (LOG_LEVEL_DEBUG <= logsys_loggers[logsys_subsys_id].priority) { \ _logsys_trace (__FILE__, __LINE__, LOGSYS_TAG_LEAVE, \ logsys_subsys_id, "<%s: " format, \ @@ -234,6 +241,7 @@ __attribute__ ((constructor)) static void logsys_subsys_init (void) \ } while(0) #define TRACE1(format, args...) do { \ + assert (logsys_subsys_id != -1); \ if (LOG_LEVEL_DEBUG <= logsys_loggers[logsys_subsys_id].priority) { \ _logsys_trace (__FILE__, __LINE__, LOGSYS_TAG_TRACE1, \ logsys_subsys_id, (format), ##args); \ @@ -241,6 +249,7 @@ __attribute__ ((constructor)) static void logsys_subsys_init (void) \ } while(0) #define TRACE2(format, args...) do { \ + assert (logsys_subsys_id != -1); \ if (LOG_LEVEL_DEBUG <= logsys_loggers[logsys_subsys_id].priority) { \ _logsys_trace (__FILE__, __LINE__, LOGSYS_TAG_TRACE2, \ logsys_subsys_id, (format), ##args); \ @@ -248,6 +257,7 @@ __attribute__ ((constructor)) static void logsys_subsys_init (void) \ } while(0) #define TRACE3(format, args...) do { \ + assert (logsys_subsys_id != -1); \ if (LOG_LEVEL_DEBUG <= logsys_loggers[logsys_subsys_id].priority) { \ _logsys_trace (__FILE__, __LINE__, LOGSYS_TAG_TRACE3, \ logsys_subsys_id, (format), ##args); \ @@ -255,6 +265,7 @@ __attribute__ ((constructor)) static void logsys_subsys_init (void) \ } while(0) #define TRACE4(format, args...) do { \ + assert (logsys_subsys_id != -1); \ if (LOG_LEVEL_DEBUG <= logsys_loggers[logsys_subsys_id].priority) { \ _logsys_trace (__FILE__, __LINE__, LOGSYS_TAG_TRACE4, \ logsys_subsys_id, (format), ##args); \ @@ -262,6 +273,7 @@ __attribute__ ((constructor)) static void logsys_subsys_init (void) \ } while(0) #define TRACE5(format, args...) do { \ + assert (logsys_subsys_id != -1); \ if (LOG_LEVEL_DEBUG <= logsys_loggers[logsys_subsys_id].priority) { \ _logsys_trace (__FILE__, __LINE__, LOGSYS_TAG_TRACE5, \ logsys_subsys_id, (format), ##args); \ @@ -269,6 +281,7 @@ __attribute__ ((constructor)) static void logsys_subsys_init (void) \ } while(0) #define TRACE6(format, args...) do { \ + assert (logsys_subsys_id != -1); \ if (LOG_LEVEL_DEBUG <= logsys_loggers[logsys_subsys_id].priority) { \ _logsys_trace (__FILE__, __LINE__, LOGSYS_TAG_TRACE6, \ logsys_subsys_id, (format), ##args); \ @@ -276,6 +289,7 @@ __attribute__ ((constructor)) static void logsys_subsys_init (void) \ } while(0) #define TRACE7(format, args...) do { \ + assert (logsys_subsys_id != -1); \ if (LOG_LEVEL_DEBUG <= logsys_loggers[logsys_subsys_id].priority) { \ _logsys_trace (__FILE__, __LINE__, LOGSYS_TAG_TRACE7, \ logsys_subsys_id, (format), ##args); \ @@ -283,6 +297,7 @@ __attribute__ ((constructor)) static void logsys_subsys_init (void) \ } while(0) #define TRACE8(format, args...) do { \ + assert (logsys_subsys_id != -1); \ if (LOG_LEVEL_DEBUG <= logsys_loggers[logsys_subsys_id].priority) { \ _logsys_trace (__FILE__, __LINE__, LOGSYS_TAG_TRACE8, \ logsys_subsys_id, (format), ##args); \ @@ -295,4 +310,10 @@ extern void _logsys_config_priority_set (unsigned int id, unsigned int priority) _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); +void logsys_exit (void); + #endif /* LOGSYS_H_DEFINED */