Przeglądaj źródła

Add support for debug level trace in config file

Because logsys uses 3-bits for log level encoded in rec, it's impossible
to add trace log level in clean way. Instead of that, we are using
recid of TRACE1 for trace messages. So if trace is allowed in
configuration file, we change old condition to log only LOGSYS_RECID_LOG
to log also LOGSYS_RECID_TRACE1.

Signed-off-by: Jan Friesse <jfriesse@redhat.com>
Reviewed-by: Fabio M. Di Nitto <fdinitto@redhat.com>
Jan Friesse 13 lat temu
rodzic
commit
842d387c2f
4 zmienionych plików z 46 dodań i 9 usunięć
  1. 29 6
      exec/logsys.c
  2. 8 2
      exec/mainconfig.c
  3. 7 0
      include/corosync/engine/logsys.h
  4. 2 1
      man/corosync.conf.5

+ 29 - 6
exec/logsys.c

@@ -144,6 +144,7 @@ struct logsys_logger {
 	int logfile_priority;			/* priority to file */
 	int logfile_priority;			/* priority to file */
 	int init_status;			/* internal field to handle init queues
 	int init_status;			/* internal field to handle init queues
 						   for subsystems */
 						   for subsystems */
+	unsigned int trace1_allowed;
 };
 };
 
 
 
 
@@ -439,13 +440,14 @@ static void log_printf_to_logs (
 	int c;
 	int c;
 	struct tm tm_res;
 	struct tm tm_res;
 
 
-	if (LOGSYS_DECODE_RECID(rec_ident) != LOGSYS_RECID_LOG) {
-		return;
-	}
-
 	subsysid = LOGSYS_DECODE_SUBSYSID(rec_ident);
 	subsysid = LOGSYS_DECODE_SUBSYSID(rec_ident);
 	level = LOGSYS_DECODE_LEVEL(rec_ident);
 	level = LOGSYS_DECODE_LEVEL(rec_ident);
 
 
+	if (!((LOGSYS_DECODE_RECID(rec_ident) == LOGSYS_RECID_LOG) ||
+	      (logsys_loggers[subsysid].trace1_allowed && LOGSYS_DECODE_RECID(rec_ident) == LOGSYS_RECID_TRACE1))) {
+		return;
+	}
+
 	while ((c = format_buffer[format_buffer_idx])) {
 	while ((c = format_buffer[format_buffer_idx])) {
 		cutoff = 0;
 		cutoff = 0;
 		if (c != '%') {
 		if (c != '%') {
@@ -960,6 +962,7 @@ int _logsys_system_setup(
 	logsys_loggers[i].mode = mode;
 	logsys_loggers[i].mode = mode;
 
 
 	logsys_loggers[i].debug = debug;
 	logsys_loggers[i].debug = debug;
+	logsys_loggers[i].trace1_allowed = 0;
 
 
 	if (logsys_config_file_set_unlocked (i, &errstr, logfile) < 0) {
 	if (logsys_config_file_set_unlocked (i, &errstr, logfile) < 0) {
 		pthread_mutex_unlock (&logsys_config_mutex);
 		pthread_mutex_unlock (&logsys_config_mutex);
@@ -1495,12 +1498,32 @@ int logsys_config_debug_set (
 	if (subsys != NULL) {
 	if (subsys != NULL) {
 		i = _logsys_config_subsys_get_unlocked (subsys);
 		i = _logsys_config_subsys_get_unlocked (subsys);
 		if (i >= 0) {
 		if (i >= 0) {
-			logsys_loggers[i].debug = debug;
+			switch (debug) {
+			case LOGSYS_DEBUG_OFF:
+			case LOGSYS_DEBUG_ON:
+				logsys_loggers[i].debug = debug;
+				logsys_loggers[i].trace1_allowed = 0;
+				break;
+			case LOGSYS_DEBUG_TRACE:
+				logsys_loggers[i].debug = LOGSYS_DEBUG_ON;
+				logsys_loggers[i].trace1_allowed = 1;
+				break;
+			}
 			i = 0;
 			i = 0;
 		}
 		}
 	} else {
 	} else {
 		for (i = 0; i <= LOGSYS_MAX_SUBSYS_COUNT; i++) {
 		for (i = 0; i <= LOGSYS_MAX_SUBSYS_COUNT; i++) {
-			logsys_loggers[i].debug = debug;
+			switch (debug) {
+			case LOGSYS_DEBUG_OFF:
+			case LOGSYS_DEBUG_ON:
+				logsys_loggers[i].debug = debug;
+				logsys_loggers[i].trace1_allowed = 0;
+				break;
+			case LOGSYS_DEBUG_TRACE:
+				logsys_loggers[i].debug = LOGSYS_DEBUG_ON;
+				logsys_loggers[i].trace1_allowed = 1;
+				break;
+			}
 		}
 		}
 		i = 0;
 		i = 0;
 	}
 	}

+ 8 - 2
exec/mainconfig.c

@@ -424,14 +424,20 @@ static int corosync_main_config_set (
 	}
 	}
 
 
 	if (!objdb_get_string (objdb, object_handle, "debug", &value)) {
 	if (!objdb_get_string (objdb, object_handle, "debug", &value)) {
+		if (strcmp (value, "trace") == 0) {
+			if (logsys_config_debug_set (subsys, LOGSYS_DEBUG_TRACE) < 0) {
+				error_reason = "unable to set debug on";
+				goto parse_error;
+			}
+		} else
 		if (strcmp (value, "on") == 0) {
 		if (strcmp (value, "on") == 0) {
-			if (logsys_config_debug_set (subsys, 1) < 0) {
+			if (logsys_config_debug_set (subsys, LOGSYS_DEBUG_ON) < 0) {
 				error_reason = "unable to set debug on";
 				error_reason = "unable to set debug on";
 				goto parse_error;
 				goto parse_error;
 			}
 			}
 		} else
 		} else
 		if (strcmp (value, "off") == 0) {
 		if (strcmp (value, "off") == 0) {
-			if (logsys_config_debug_set (subsys, 0) < 0) {
+			if (logsys_config_debug_set (subsys, LOGSYS_DEBUG_OFF) < 0) {
 				error_reason = "unable to set debug off";
 				error_reason = "unable to set debug off";
 				goto parse_error;
 				goto parse_error;
 			}
 			}

+ 7 - 0
include/corosync/engine/logsys.h

@@ -58,6 +58,7 @@ extern "C" {
 #define LOGSYS_MODE_FORK		(1<<3)
 #define LOGSYS_MODE_FORK		(1<<3)
 #define LOGSYS_MODE_THREADED		(1<<4)
 #define LOGSYS_MODE_THREADED		(1<<4)
 
 
+
 /*
 /*
  * Log priorities, compliant with syslog and SA Forum Log spec.
  * Log priorities, compliant with syslog and SA Forum Log spec.
  */
  */
@@ -92,6 +93,12 @@ extern "C" {
 #define LOGSYS_RECID_TRACE7		(LOGSYS_RECID_MAX - 10)
 #define LOGSYS_RECID_TRACE7		(LOGSYS_RECID_MAX - 10)
 #define LOGSYS_RECID_TRACE8		(LOGSYS_RECID_MAX - 11)
 #define LOGSYS_RECID_TRACE8		(LOGSYS_RECID_MAX - 11)
 
 
+/*
+ * Debug levels
+ */
+#define LOGSYS_DEBUG_OFF		0
+#define LOGSYS_DEBUG_ON			1
+#define LOGSYS_DEBUG_TRACE		2
 
 
 /*
 /*
  * Internal APIs that must be globally exported
  * Internal APIs that must be globally exported

+ 2 - 1
man/corosync.conf.5

@@ -601,7 +601,8 @@ The default is: info.
 
 
 .TP
 .TP
 debug
 debug
-This specifies whether debug output is logged for this particular logger.
+This specifies whether debug output is logged for this particular logger. Also can contain
+value trace, what is highest level of debug informations.
 
 
 The default is off.
 The default is off.