Просмотр исходного кода

Fix logsys TAG handling

git-svn-id: http://svn.fedorahosted.org/svn/corosync/trunk@2180 fd59a12c-fef9-0310-b244-a6a79926bd2f
Fabio M. Di Nitto 17 лет назад
Родитель
Сommit
75c9085204
4 измененных файлов с 103 добавлено и 76 удалено
  1. 46 24
      exec/logsys.c
  2. 2 2
      exec/main.c
  3. 42 27
      include/corosync/engine/logsys.h
  4. 13 23
      tools/corosync-fplay.c

+ 46 - 24
exec/logsys.c

@@ -421,6 +421,7 @@ static void log_printf_to_logs (
 	const char *function_name,
 	int file_line,
 	unsigned int level,
+	unsigned int tag,
 	const char *buffer)
 {
 	char output_buffer[COMBINE_BUFFER_SIZE];
@@ -432,13 +433,23 @@ static void log_printf_to_logs (
 	size_t cutoff;
 	unsigned int len;
 	int subsysid;
+	int c, i, has_tag = 0;
 
 	subsysid = _logsys_config_subsys_get(subsys);
 	if (subsysid <= - 1) {
 		return;
 	}
 
-	int c;
+	for (i = 1; tagnames[i].c_name != NULL; i++) {
+		if (tag & tagnames[i].c_val) {
+			if ((logsys_loggers[subsysid].tags & tag) == 0) {
+				return;
+			} else {
+				has_tag = 1;
+			}
+		}
+	}
+
 	while ((c = format_buffer[format_buffer_idx])) {
 		cutoff = 0;
 		if (c != '%') {
@@ -507,7 +518,7 @@ static void log_printf_to_logs (
 	 */
 	if ((logsys_loggers[subsysid].mode & LOGSYS_MODE_OUTPUT_SYSLOG) &&
 	     ((level <= logsys_loggers[subsysid].syslog_priority) ||
-	     (logsys_loggers[subsysid].debug != 0))) {
+	     (logsys_loggers[subsysid].debug != 0) || (has_tag > 0))) {
 		syslog (level | logsys_loggers[subsysid].syslog_facility, "%s", output_buffer);
 	}
 
@@ -523,7 +534,7 @@ static void log_printf_to_logs (
 	if (((logsys_loggers[subsysid].mode & LOGSYS_MODE_OUTPUT_FILE) &&
 	     (logsys_loggers[subsysid].logfile_fp != NULL)) &&
 	    ((level <= logsys_loggers[subsysid].logfile_priority) ||
-	     (logsys_loggers[subsysid].debug != 0))) {
+	     (logsys_loggers[subsysid].debug != 0) || (has_tag > 0))) {
 		/*
 		 * Output to a file
 		 */
@@ -546,7 +557,7 @@ static void log_printf_to_logs (
 			pthread_mutex_unlock (&logsys_config_mutex);
 			log_printf_to_logs(logsys_loggers[subsysid].subsys,
 					   __FILE__, __FUNCTION__, __LINE__,
-					   LOGSYS_LEVEL_EMERG, tmpbuffer);
+					   LOGSYS_LEVEL_EMERG, 0, tmpbuffer);
 		}
 	}
 
@@ -555,7 +566,7 @@ static void log_printf_to_logs (
 	 */
 	if ((logsys_loggers[subsysid].mode & LOGSYS_MODE_OUTPUT_STDERR) &&
 	     ((level <= logsys_loggers[subsysid].logfile_priority) ||
-	     (logsys_loggers[subsysid].debug != 0))) {
+	     (logsys_loggers[subsysid].debug != 0) || (has_tag > 0))) {
 		if (write (STDERR_FILENO, output_buffer, strlen (output_buffer)) < 0) {
 			char tmpbuffer[1024];
 			/*
@@ -571,7 +582,7 @@ static void log_printf_to_logs (
 				logsys_loggers[subsysid].subsys);
 			log_printf_to_logs(logsys_loggers[subsysid].subsys,
 				__FILE__, __FUNCTION__, __LINE__,
-				LOGSYS_LEVEL_EMERG, tmpbuffer);
+				LOGSYS_LEVEL_EMERG, 0, tmpbuffer);
 		}
 	}
 }
@@ -580,17 +591,17 @@ static void record_print (const char *buf)
 {
 	const int *buf_uint32t = (const int *)buf;
 	unsigned int rec_size = buf_uint32t[0];
-	unsigned int rec_ident = buf_uint32t[1];
-	unsigned int file_line = buf_uint32t[2];
-	unsigned int level = rec_ident >> 28;
+	unsigned int level = buf_uint32t[1];
+	unsigned int tag = buf_uint32t[2];
+	unsigned int file_line = buf_uint32t[3];
 	unsigned int i;
 	unsigned int words_processed;
 	unsigned int arg_size_idx;
 	const void *arguments[64];
 	unsigned int arg_count;
 
-	arg_size_idx = 4;
-	words_processed = 4;
+	arg_size_idx = 5;
+	words_processed = 5;
 	arg_count = 0;
 
 	for (i = 0; words_processed < rec_size; i++) {
@@ -611,22 +622,25 @@ static void record_print (const char *buf)
 		(char *)arguments[1],
 		(char *)arguments[2],
 		file_line,
-		(level-1),
+		level,
+		tag,
 		(char *)arguments[3]);
 }
 
 static int record_read (char *buf, int rec_idx, int *log_msg) {
-        unsigned int rec_size;
-        unsigned int rec_ident;
-        int firstcopy, secondcopy;
+	unsigned int rec_size;
+	unsigned int rec_ident;
+	unsigned int tag;
+	int firstcopy, secondcopy;
 
 	rec_size = flt_data[rec_idx];
 	rec_ident = flt_data[(rec_idx + 1) % flt_data_size];
+	tag = flt_data[(rec_idx + 2) % flt_data_size];
 
 	/*
 	 * Not a log record
 	 */
-	if ((rec_ident & LOGSYS_TAG_LOG) == 0) {
+	if ((tag & LOGSYS_TAG_LOG) == 0) {
 		*log_msg = 0;
         	return ((rec_idx + rec_size) % flt_data_size);
 	}
@@ -898,7 +912,6 @@ static void logsys_subsys_init (
 		memcpy(&logsys_loggers[subsysid],
 		       &logsys_loggers[LOGSYS_MAX_SUBSYS_COUNT],
 		       sizeof(logsys_loggers[LOGSYS_MAX_SUBSYS_COUNT]));
-		logsys_loggers[subsysid].tags = LOGSYS_TAG_LOG;
 		logsys_loggers[subsysid].init_status =
 			LOGSYS_LOGGER_INIT_DONE;
 	}
@@ -1051,12 +1064,14 @@ int _logsys_rec_init (unsigned int size)
  * buffer arg1
  * ... repeats length & arg
  */
+
 void _logsys_log_rec (
 	int subsysid,
 	const char *function_name,
 	const char *file_name,
 	int file_line,
 	unsigned int rec_ident,
+	unsigned int tag,
 	...)
 {
 	va_list ap;
@@ -1074,7 +1089,7 @@ void _logsys_log_rec (
 	/*
 	 * Decode VA Args
 	 */
-	va_start (ap, rec_ident);
+	va_start (ap, tag);
 	arguments = 3;
 	for (;;) {
 		buf_args[arguments] = va_arg (ap, void *);
@@ -1109,7 +1124,7 @@ void _logsys_log_rec (
 	/*
 	 * Reclaim data needed for record including 4 words for the header
 	 */
-	records_reclaim (idx, record_reclaim_size + 4);
+	records_reclaim (idx, record_reclaim_size + 5);
 
 	/*
 	 * Write record size of zero and rest of header information
@@ -1120,6 +1135,9 @@ void _logsys_log_rec (
 	flt_data[idx++] = rec_ident;
 	idx_word_step(idx);
 
+	flt_data[idx++] = tag;
+	idx_word_step(idx);
+
 	flt_data[idx++] = file_line;
 	idx_word_step(idx);
 
@@ -1194,7 +1212,7 @@ void _logsys_log_rec (
 	 * the new head position and commit the new head.
 	 */
 	logsys_lock();
-	if (rec_ident & LOGSYS_TAG_LOG) {
+	if (tag & LOGSYS_TAG_LOG) {
 		log_requests_pending += 1;
 	}
 	if (log_requests_pending == 0) {
@@ -1211,6 +1229,7 @@ void _logsys_log_vprintf (
 	const char *file_name,
 	int file_line,
 	unsigned int level,
+	unsigned int tag,
 	const char *format,
 	va_list ap)
 {
@@ -1240,7 +1259,8 @@ void _logsys_log_vprintf (
 		function_name,
 		file_name,
 		file_line,
-		(level+1) << 28,
+		level,
+		tag |= LOGSYS_TAG_LOG,
 		logsys_print_buffer, len + 1,
 		LOGSYS_REC_END);
 
@@ -1250,7 +1270,7 @@ void _logsys_log_vprintf (
 		 * expect the worker thread to output the log data once signaled
 		 */
 		log_printf_to_logs (logsys_loggers[subsysid].subsys,
-			file_name, function_name, file_line, level,
+			file_name, function_name, file_line, level, tag,
 			logsys_print_buffer);
 	} else {
 		/*
@@ -1266,6 +1286,7 @@ void _logsys_log_printf (
 	const char *file_name,
 	int file_line,
 	unsigned int level,
+	unsigned int tag,
 	const char *format,
 	...)
 {
@@ -1298,7 +1319,8 @@ void _logsys_log_printf (
 		function_name,
 		file_name,
 		file_line,
-		(level+1) << 28,
+		level,
+		tag |= LOGSYS_TAG_LOG,
 		logsys_print_buffer, len + 1,
 		LOGSYS_REC_END);
 
@@ -1308,7 +1330,7 @@ void _logsys_log_printf (
 		 * expect the worker thread to output the log data once signaled
 		 */
 		log_printf_to_logs (logsys_loggers[subsysid].subsys,
-			file_name, function_name, file_line, level,
+			file_name, function_name, file_line, level, tag,
 			logsys_print_buffer);
 	} else {
 		/*

+ 2 - 2
exec/main.c

@@ -547,14 +547,14 @@ static void ipc_log_printf (const char *format, ...) {
 	va_start (ap, format);
 
 	_logsys_log_vprintf (ipc_subsys_id, __FUNCTION__,
-		__FILE__, __LINE__, LOGSYS_LEVEL_ERROR, format, ap);
+		__FILE__, __LINE__, LOGSYS_LEVEL_ERROR, 0, format, ap);
 
 	va_end (ap);
 }
 
 static void ipc_fatal_error(const char *error_msg) {
        _logsys_log_printf (ipc_subsys_id, __FUNCTION__,
-                __FILE__, __LINE__, LOGSYS_LEVEL_ERROR, "%s", error_msg);
+                __FILE__, __LINE__, LOGSYS_LEVEL_ERROR, 0, "%s", error_msg);
 	exit(EXIT_FAILURE);
 }
 

+ 42 - 27
include/corosync/engine/logsys.h

@@ -76,17 +76,17 @@ extern "C" {
  * LOG is mandatory, but enforced, for subsystems.
  * Be careful if/when changing tags at runtime.
  */
-#define LOGSYS_TAG_LOG			(0xff<<28)
-#define LOGSYS_TAG_ENTER		(1<<27)
-#define LOGSYS_TAG_LEAVE		(1<<26)
-#define LOGSYS_TAG_TRACE1		(1<<25)
-#define LOGSYS_TAG_TRACE2		(1<<24)
-#define LOGSYS_TAG_TRACE3		(1<<23)
-#define LOGSYS_TAG_TRACE4		(1<<22)
-#define LOGSYS_TAG_TRACE5		(1<<21)
-#define LOGSYS_TAG_TRACE6		(1<<20)
-#define LOGSYS_TAG_TRACE7		(1<<19)
-#define LOGSYS_TAG_TRACE8		(1<<18)
+#define LOGSYS_TAG_LOG			(1<<0)
+#define LOGSYS_TAG_ENTER		(1<<1)
+#define LOGSYS_TAG_LEAVE		(1<<2)
+#define LOGSYS_TAG_TRACE1		(1<<3)
+#define LOGSYS_TAG_TRACE2		(1<<4)
+#define LOGSYS_TAG_TRACE3		(1<<5)
+#define LOGSYS_TAG_TRACE4		(1<<6)
+#define LOGSYS_TAG_TRACE5		(1<<7)
+#define LOGSYS_TAG_TRACE6		(1<<8)
+#define LOGSYS_TAG_TRACE7		(1<<9)
+#define LOGSYS_TAG_TRACE8		(1<<10)
 
 /*
  * Internal APIs that must be globally exported
@@ -125,8 +125,9 @@ extern void _logsys_log_vprintf (
 	const char *file_name,
 	int file_line,
 	unsigned int level,
+	unsigned int tag,
 	const char *format,
-	va_list ap) __attribute__((format(printf, 6, 0)));
+	va_list ap) __attribute__((format(printf, 7, 0)));
 
 extern void _logsys_log_printf (
 	int subsysid,
@@ -134,8 +135,9 @@ extern void _logsys_log_printf (
 	const char *file_name,
 	int file_line,
 	unsigned int level,
+	unsigned int tag,
 	const char *format,
-	...) __attribute__((format(printf, 6, 7)));
+	...) __attribute__((format(printf, 7, 8)));
 
 extern void _logsys_log_rec (
 	int subsysid,
@@ -143,6 +145,7 @@ extern void _logsys_log_rec (
 	const char *file_name,
 	int file_line,
 	unsigned int rec_ident,
+	unsigned int tag,
 	...);
 
 extern int _logsys_wthread_create (void);
@@ -315,63 +318,75 @@ static void logsys_subsys_init (void)					\
 #define log_rec(rec_ident, args...)					\
 do {									\
 	_logsys_log_rec (logsys_subsys_id,  __FUNCTION__,		\
-		__FILE__,  __LINE__, rec_ident, ##args);		\
+		__FILE__,  __LINE__, rec_ident, 0, ##args);		\
 } while(0)
 
 #define log_printf(lvl, format, args...)				\
  do {									\
 	_logsys_log_printf (logsys_subsys_id, __FUNCTION__,		\
-		__FILE__, __LINE__, lvl, format, ##args);		\
+		__FILE__, __LINE__, lvl, 0, format, ##args);		\
 } while(0)
 
 #define ENTER() do {							\
-	_logsys_log_rec (logsys_subsys_id, __FUNCTION__,		\
-		__FILE__,  __LINE__, LOGSYS_TAG_ENTER, LOGSYS_REC_END);	\
+	_logsys_log_printf (logsys_subsys_id, __FUNCTION__,		\
+		__FILE__,  __LINE__, LOGSYS_LEVEL_DEBUG, 		\
+		LOGSYS_TAG_ENTER, "ENTERING function [%s] line [%d]\n", \
+		__FUNCTION__, __LINE__);				\
 } while(0)
 
 #define LEAVE() do {							\
-	_logsys_log_rec (logsys_subsys_id, __FUNCTION__,		\
-		__FILE__,  __LINE__, LOGSYS_TAG_LEAVE, LOGSYS_REC_END);	\
+	_logsys_log_printf (logsys_subsys_id, __FUNCTION__,		\
+		__FILE__,  __LINE__, LOGSYS_LEVEL_DEBUG,		\
+		LOGSYS_TAG_LEAVE, "LEAVING function [%s] line [%d]\n",	\
+		__FUNCTION__, __LINE__);				\
 } while(0)
 
 #define TRACE1(format, args...) do {					\
 	_logsys_log_printf (logsys_subsys_id, __FUNCTION__,		\
-		__FILE__,  __LINE__, LOGSYS_TAG_TRACE1, format, ##args);\
+		__FILE__,  __LINE__, LOGSYS_LEVEL_DEBUG, 		\
+		LOGSYS_TAG_TRACE1, format, ##args);			\
 } while(0)
 
 #define TRACE2(format, args...) do {					\
 	_logsys_log_printf (logsys_subsys_id, __FUNCTION__,		\
-		__FILE__,  __LINE__, LOGSYS_TAG_TRACE2, format, ##args);\
+		__FILE__,  __LINE__, LOGSYS_LEVEL_DEBUG,		\
+		LOGSYS_TAG_TRACE2, format, ##args);			\
 } while(0)
 
 #define TRACE3(format, args...) do {					\
 	_logsys_log_printf (logsys_subsys_id, __FUNCTION__,		\
-		__FILE__,  __LINE__, LOGSYS_TAG_TRACE3, format, ##args);\
+		__FILE__,  __LINE__, LOGSYS_LEVEL_DEBUG,		\
+		LOGSYS_TAG_TRACE3, format, ##args);			\
 } while(0)
 
 #define TRACE4(format, args...) do {					\
 	_logsys_log_printf (logsys_subsys_id, __FUNCTION__,		\
-		__FILE__,  __LINE__, LOGSYS_TAG_TRACE4, format, ##args);\
+		__FILE__,  __LINE__, LOGSYS_LEVEL_DEBUG,		\
+		LOGSYS_TAG_TRACE4, format, ##args);			\
 } while(0)
 
 #define TRACE5(format, args...) do {					\
 	_logsys_log_printf (logsys_subsys_id, __FUNCTION__,		\
-		__FILE__,  __LINE__, LOGSYS_TAG_TRACE5, format, ##args);\
+		__FILE__,  __LINE__, LOGSYS_LEVEL_DEBUG,		\
+		LOGSYS_TAG_TRACE5, format, ##args);			\
 } while(0)
 
 #define TRACE6(format, args...) do {					\
 	_logsys_log_printf (logsys_subsys_id, __FUNCTION__,		\
-		__FILE__,  __LINE__, LOGSYS_TAG_TRACE6, format, ##args);\
+		__FILE__,  __LINE__, LOGSYS_LEVEL_DEBUG,		\
+		LOGSYS_TAG_TRACE6, format, ##args);			\
 } while(0)
 
 #define TRACE7(format, args...) do {					\
 	_logsys_log_printf (logsys_subsys_id, __FUNCTION__,		\
-		__FILE__,  __LINE__, LOGSYS_TAG_TRACE7, format, ##args);\
+		__FILE__,  __LINE__, LOGSYS_LEVEL_DEBUG,		\
+		LOGSYS_TAG_TRACE7, format, ##args);			\
 } while(0)
 
 #define TRACE8(format, args...) do {					\
 	_logsys_log_printf (logsys_subsys_id, __FUNCTION__,		\
-		__FILE__,  __LINE__, LOGSYS_TAG_TRACE8, format, ##args);\
+		__FILE__,  __LINE__, LOGSYS_LEVEL_DEBUG,		\
+		LOGSYS_TAG_TRACE8, format, ##args);			\
 } while(0)
 
 #ifdef __cplusplus

+ 13 - 23
tools/corosync-fplay.c

@@ -371,6 +371,7 @@ static void logsys_rec_print (const void *record)
 	const unsigned int *buf_uint32t = record;
 	unsigned int rec_size;
 	unsigned int rec_ident;
+	unsigned int tag;
 	unsigned int line;
 	unsigned int arg_size_idx;
 	unsigned int i;
@@ -384,12 +385,13 @@ static void logsys_rec_print (const void *record)
 
 	rec_size = buf_uint32t[rec_idx];
 	rec_ident = buf_uint32t[rec_idx+1];
-	line = buf_uint32t[rec_idx+2];
-	record_number = buf_uint32t[rec_idx+3];
+	tag = buf_uint32t[rec_idx+2];
+	line = buf_uint32t[rec_idx+3];
+	record_number = buf_uint32t[rec_idx+4];
 
-printf ("rec=[%d] ", record_number);
-	arg_size_idx = rec_idx + 4;
-	words_processed = 4;
+	printf ("rec=[%d] ", record_number);
+	arg_size_idx = rec_idx + 5;
+	words_processed = 5;
 	for (i = 0; words_processed < rec_size; i++) {
 		arguments[arg_count++] =
 		  (const char *)&buf_uint32t[arg_size_idx + 1];
@@ -409,30 +411,19 @@ printf ("rec=[%d] ", record_number);
 			}
 		}
 	}
-	if (rec_ident & LOGSYS_TAG_LOG) {
-		printf ("Log Message=%s\n", arguments[3]);
-		found = 1;
-	}
-	if (rec_ident & LOGSYS_TAG_ENTER) {
+	if (tag & LOGSYS_TAG_ENTER) {
 		printf ("ENTERING function [%s] line [%d]\n", arguments[2], line);
 		found = 1;
 	}
-	if (rec_ident & LOGSYS_TAG_LEAVE) {
+	if (tag & LOGSYS_TAG_LEAVE) {
 		printf ("LEAVING function [%s] line [%d]\n", arguments[2], line);
 		found = 1;
 	}
-	if (found == 0) {
-		printf ("Unknown record type found subsys=[%s] ident=[%d]\n",
-			arguments[0], rec_ident);
-	}
-
-
-	if (rec_ident == 999) {
-		printf ("ENTERING function [%s] line [%d]\n", arguments[2], line);
-		found = 1;
+	if (found == 1) {
+		tag &= ~LOGSYS_TAG_LOG;
 	}
-	if (rec_ident == 1000) {
-		printf ("LEAVING function [%s] line [%d]\n", arguments[2], line);
+	if (tag & LOGSYS_TAG_LOG) {
+		printf ("Log Message=%s\n", arguments[3]);
 		found = 1;
 	}
 	if (found == 0) {
@@ -440,7 +431,6 @@ printf ("rec=[%d] ", record_number);
 			arguments[0], rec_ident);
 	}
 
-
 #ifdef COMPILE_OUT
 printf ("\n");
 #endif