Sfoglia il codice sorgente

logsys: Support hires timestamp

Signed-off-by: Jan Friesse <jfriesse@redhat.com>
Reviewed-by: Christine Caulfield <ccaulfie@redhat.com>
Jan Friesse 7 anni fa
parent
commit
bd2fff5bb3
3 ha cambiato i file con 33 aggiunte e 15 eliminazioni
  1. 9 2
      exec/logconfig.c
  2. 20 11
      exec/logsys.c
  3. 4 2
      man/corosync.conf.5

+ 9 - 2
exec/logconfig.c

@@ -203,8 +203,15 @@ static int corosync_main_config_format_set (
 					"%t ", NULL)) {
 				err = logsys_format_set(new_format_buffer);
 			}
-		} else
-		if (strcmp (value, "off") == 0) {
+#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);
+			}
+#endif
+		} else if (strcmp (value, "off") == 0) {
 			/* nothing to do here */
 		} else {
 			error_reason = "unknown value for timestamp";

+ 20 - 11
exec/logsys.c

@@ -567,17 +567,25 @@ int logsys_config_file_set (
 static void
 logsys_file_format_get(char* file_format, int buf_len)
 {
-	char *per_t;
+	char *format_buffer_start;
+	char *str_pos;
+
 	file_format[0] = '\0';
-	per_t = strstr(format_buffer, "%t");
-	if (per_t) {
-		strcpy(file_format, "%t [%P] %H %N");
-		per_t += 2;
-		strncat(file_format, per_t, buf_len - strlen("%t [%P] %H %N"));
-	} else {
-		strcpy(file_format, "[%P] %H %N");
-		strncat(file_format, format_buffer, buf_len - strlen("[%P] %H %N"));
+
+	format_buffer_start = format_buffer;
+
+	if ((str_pos = strstr(format_buffer, "%t"))) {
+		strcpy(file_format, "%t ");
+		format_buffer_start = str_pos + 2;
 	}
+
+	if ((str_pos = strstr(format_buffer, "%T"))) {
+		strcpy(file_format, "%T ");
+		format_buffer_start = str_pos + 2;
+	}
+
+	strcat(file_format, "[%P] %H %N");
+	strncat(file_format, format_buffer_start, buf_len - strlen(file_format));
 }
 
 int logsys_format_set (const char *format)
@@ -609,7 +617,7 @@ int logsys_format_set (const char *format)
 	}
 
 	/*
-	 * This just goes through and remove %t and %p from
+	 * This just goes through and remove %t, %T and %p from
 	 * the format string for syslog.
 	 */
 	w = 0;
@@ -622,7 +630,8 @@ int logsys_format_set (const char *format)
 					continue;
 				}
 				if (format_buffer[c] == 't' ||
-				    format_buffer[c] == 'p') {
+				    format_buffer[c] == 'p' ||
+				    format_buffer[c] == 'T') {
 					c++;
 				} else {
 					c = reminder;

+ 4 - 2
man/corosync.conf.5

@@ -32,7 +32,7 @@
 .\" * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
 .\" * THE POSSIBILITY OF SUCH DAMAGE.
 .\" */
-.TH COROSYNC_CONF 5 2018-10-02 "corosync Man Page" "Corosync Cluster Engine Programmer's Manual"
+.TH COROSYNC_CONF 5 2018-10-26 "corosync Man Page" "Corosync Cluster Engine Programmer's Manual"
 .SH NAME
 corosync.conf - corosync executive configuration file
 
@@ -525,7 +525,9 @@ The following 3 options are valid only for the top level logging directive:
 
 .TP
 timestamp
-This specifies that a timestamp is placed on all log messages.
+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.