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

logsys: Make hires timestamp default

Signed-off-by: Jan Friesse <jfriesse@redhat.com>
Reviewed-by: Christine Caulfield <ccaulfie@redhat.com>
Jan Friesse 7 лет назад
Родитель
Сommit
48cb28b0a4
3 измененных файлов с 25 добавлено и 13 удалено
  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
 	# Log debug messages (very verbose). When in doubt, leave 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 {
 		subsys: QUORUM
 		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 *value = NULL;
 	int err = 0;
+	char timestamp_str_to_add[8];
 
 	if (map_get_string("logging.fileline", &value) == CS_OK) {
 		if (strcmp (value, "on") == 0) {
@@ -196,20 +197,14 @@ static int corosync_main_config_format_set (
 		goto parse_error;
 	}
 
+	memset(timestamp_str_to_add, 0, sizeof(timestamp_str_to_add));
+
 	if (map_get_string("logging.timestamp", &value) == CS_OK) {
 		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
 		} 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
 		} else if (strcmp (value, "off") == 0) {
 			/* nothing to do here */
@@ -220,6 +215,23 @@ static int corosync_main_config_format_set (
 		}
 
 		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) {

+ 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
 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
 fileline