From 7572a68eaa7a4f311c6545ca2cf84489f4a9ec84 Mon Sep 17 00:00:00 2001 From: Tim Stack Date: Tue, 15 Aug 2023 21:14:37 -0700 Subject: [PATCH] [date_time] do not change time format if there is a loss of precision --- src/log_format.cc | 21 +++++++++++++++++++++ src/logfile_sub_source.cc | 13 +++++++------ 2 files changed, 28 insertions(+), 6 deletions(-) diff --git a/src/log_format.cc b/src/log_format.cc index 8a12bb70..676b3ed0 100644 --- a/src/log_format.cc +++ b/src/log_format.cc @@ -72,6 +72,9 @@ external_log_format::mod_map_t external_log_format::MODULE_FORMATS; std::vector> external_log_format::GRAPH_ORDERED_FORMATS; +static const uint32_t DATE_TIME_SET_FLAGS = ETF_YEAR_SET | ETF_MONTH_SET + | ETF_DAY_SET | ETF_HOUR_SET | ETF_MINUTE_SET | ETF_SECOND_SET; + log_level_stats& log_level_stats::operator|=(const log_level_stats& rhs) { @@ -643,8 +646,26 @@ log_format::log_scanf(uint32_t line_number, auto ls = this->lf_date_time.unlock(); retval = this->lf_date_time.scan( ts->data(), ts->length(), nullptr, tm_out, *tv_out); + if (retval != nullptr) { + auto old_flags + = this->lf_timestamp_flags & DATE_TIME_SET_FLAGS; + auto new_flags = tm_out->et_flags & DATE_TIME_SET_FLAGS; + + // It is unlikely a valid timestamp would lose much + // precision. + if (new_flags != old_flags) { + retval = nullptr; + } + } if (retval == nullptr) { this->lf_date_time.relock(ls); + } else { + log_debug( + "%d: changed time format to '%s' due to %.*s", + line_number, + PTIMEC_FORMAT_STR[this->lf_date_time.dts_fmt_lock], + ts->length(), + ts->data()); } } diff --git a/src/logfile_sub_source.cc b/src/logfile_sub_source.cc index d51e87b1..856919a5 100644 --- a/src/logfile_sub_source.cc +++ b/src/logfile_sub_source.cc @@ -273,12 +273,13 @@ logfile_sub_source::text_value_for_line(textview_curses& tc, value_out = this->lss_token_value; } - if ((this->lss_token_file->is_time_adjusted() - || (format->lf_timestamp_flags & ETF_ZONE_SET - && format->lf_date_time.dts_zoned_to_local) - || format->lf_timestamp_flags & ETF_MACHINE_ORIENTED - || !(format->lf_timestamp_flags & ETF_DAY_SET) - || !(format->lf_timestamp_flags & ETF_MONTH_SET)) + if (!this->lss_token_line->is_continued() + && (this->lss_token_file->is_time_adjusted() + || (format->lf_timestamp_flags & ETF_ZONE_SET + && format->lf_date_time.dts_zoned_to_local) + || format->lf_timestamp_flags & ETF_MACHINE_ORIENTED + || !(format->lf_timestamp_flags & ETF_DAY_SET) + || !(format->lf_timestamp_flags & ETF_MONTH_SET)) && format->lf_date_time.dts_fmt_lock != -1) { auto time_attr