From bd2fff5bb343c7793616cadfa08f1a9c13f0c84b Mon Sep 17 00:00:00 2001 From: Jan Friesse Date: Fri, 26 Oct 2018 15:39:10 +0200 Subject: [PATCH] logsys: Support hires timestamp Signed-off-by: Jan Friesse Reviewed-by: Christine Caulfield --- exec/logconfig.c | 11 +++++++++-- exec/logsys.c | 31 ++++++++++++++++++++----------- man/corosync.conf.5 | 6 ++++-- 3 files changed, 33 insertions(+), 15 deletions(-) diff --git a/exec/logconfig.c b/exec/logconfig.c index c70e6862..0f711d10 100644 --- a/exec/logconfig.c +++ b/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"; diff --git a/exec/logsys.c b/exec/logsys.c index 51f488ad..12f6af95 100644 --- a/exec/logsys.c +++ b/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; diff --git a/man/corosync.conf.5 b/man/corosync.conf.5 index 8cc9a763..06707dc4 100644 --- a/man/corosync.conf.5 +++ b/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.