Selaa lähdekoodia

logsys: Make hires timestamp default

Signed-off-by: Jan Friesse <jfriesse@redhat.com>
Reviewed-by: Christine Caulfield <ccaulfie@redhat.com>
Jan Friesse 7 vuotta sitten
vanhempi
commit
48cb28b0a4
3 muutettua tiedostoa jossa 25 lisäystä ja 13 poistoa
  1. 2 2
      conf/corosync.conf.example
  2. 22 10
      exec/logconfig.c
  3. 1 1
      man/corosync.conf.5

+ 2 - 2
conf/corosync.conf.example

@@ -28,8 +28,8 @@ logging {
 	to_syslog: yes
 	to_syslog: yes
 	# Log debug messages (very verbose). When in doubt, leave off.
 	# Log debug messages (very verbose). When in doubt, leave off.
 	debug: off
 	debug: off
-	# Log messages with time stamps. When in doubt, set to on
-	timestamp: on
+	# Log messages with time stamps. When in doubt, set to hires (or on)
+	#timestamp: hires
 	logger_subsys {
 	logger_subsys {
 		subsys: QUORUM
 		subsys: QUORUM
 		debug: off
 		debug: off

+ 22 - 10
exec/logconfig.c

@@ -137,6 +137,7 @@ static int corosync_main_config_format_set (
 	char new_format_buffer[PATH_MAX];
 	char new_format_buffer[PATH_MAX];
 	char *value = NULL;
 	char *value = NULL;
 	int err = 0;
 	int err = 0;
+	char timestamp_str_to_add[8];
 
 
 	if (map_get_string("logging.fileline", &value) == CS_OK) {
 	if (map_get_string("logging.fileline", &value) == CS_OK) {
 		if (strcmp (value, "on") == 0) {
 		if (strcmp (value, "on") == 0) {
@@ -196,20 +197,14 @@ static int corosync_main_config_format_set (
 		goto parse_error;
 		goto parse_error;
 	}
 	}
 
 
+	memset(timestamp_str_to_add, 0, sizeof(timestamp_str_to_add));
+
 	if (map_get_string("logging.timestamp", &value) == CS_OK) {
 	if (map_get_string("logging.timestamp", &value) == CS_OK) {
 		if (strcmp (value, "on") == 0) {
 		if (strcmp (value, "on") == 0) {
-			if(!insert_into_buffer(new_format_buffer,
-					sizeof(new_format_buffer),
-					"%t ", NULL)) {
-				err = logsys_format_set(new_format_buffer);
-			}
+			strcpy(timestamp_str_to_add, "%t");
 #ifdef QB_FEATURE_LOG_HIRES_TIMESTAMPS
 #ifdef QB_FEATURE_LOG_HIRES_TIMESTAMPS
 		} else if (strcmp (value, "hires") == 0) {
 		} else if (strcmp (value, "hires") == 0) {
-			if(!insert_into_buffer(new_format_buffer,
-					sizeof(new_format_buffer),
-					"%T ", NULL)) {
-				err = logsys_format_set(new_format_buffer);
-			}
+			strcpy(timestamp_str_to_add, "%T");
 #endif
 #endif
 		} else if (strcmp (value, "off") == 0) {
 		} else if (strcmp (value, "off") == 0) {
 			/* nothing to do here */
 			/* nothing to do here */
@@ -220,6 +215,23 @@ static int corosync_main_config_format_set (
 		}
 		}
 
 
 		free(value);
 		free(value);
+	} else {
+		/*
+		 * Display hires timestamp by default, otherwise standard timestamp
+		 */
+#ifdef QB_FEATURE_LOG_HIRES_TIMESTAMPS
+		strcpy(timestamp_str_to_add, "%T");
+#else
+		strcpy(timestamp_str_to_add, "%t");
+#endif
+	}
+
+	if(strcmp(timestamp_str_to_add, "") != 0) {
+		strcat(timestamp_str_to_add, " ");
+		if (insert_into_buffer(new_format_buffer, sizeof(new_format_buffer),
+		    timestamp_str_to_add, NULL) == 0) {
+			err = logsys_format_set(new_format_buffer);
+		}
 	}
 	}
 
 
 	if (err) {
 	if (err) {

+ 1 - 1
man/corosync.conf.5

@@ -529,7 +529,7 @@ This specifies that a timestamp is placed on all log messages. It can be one
 of off (no timestamp), on (second precision timestamp) or
 of off (no timestamp), on (second precision timestamp) or
 hires (millisecond precision timestamp - only when supported by LibQB).
 hires (millisecond precision timestamp - only when supported by LibQB).
 
 
-The default is off.
+The default is hires (or on if hires is not supported).
 
 
 .TP
 .TP
 fileline
 fileline