From cc28cd68160f609bca0891f29c8228bbdc056685 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sun, 17 Jan 2021 17:44:51 +0100 Subject: [PATCH] Fix logging when timestamps are disabled after recent changes The changes of 1065e61ab7 (Merge branch 'log-ms', 2021-01-16) broke logging when timestamps were disabled as they still tried to format the timestamp in this case, using empty timestamp, which resulted in an assert. Fix this and also make new code more similar to the existing one by adding wxLog::TimeStampMS() helper parallel to the already existing TimeStamp() and write it in the same way -- which notably ensures that it does nothing when the timestamp is empty. See #13059. --- include/wx/log.h | 1 + src/common/log.cpp | 18 ++++++++++++++---- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/include/wx/log.h b/include/wx/log.h index 5e82ac232d..f3552e9724 100644 --- a/include/wx/log.h +++ b/include/wx/log.h @@ -533,6 +533,7 @@ public: // change it otherwise); the first overload uses the current time. static void TimeStamp(wxString *str); static void TimeStamp(wxString *str, time_t t); + static void TimeStampMS(wxString *str, wxLongLong_t msec); // these methods should only be called from derived classes DoLogRecord(), // DoLogTextAtLevel() and DoLogText() implementations respectively and diff --git a/src/common/log.cpp b/src/common/log.cpp index 8978ca5f77..6f544148c2 100644 --- a/src/common/log.cpp +++ b/src/common/log.cpp @@ -264,10 +264,7 @@ wxLogFormatter::FormatTimeMS(wxLongLong_t msec) const { wxString str; -#if wxUSE_DATETIME - str = wxDateTime(wxLongLong(msec)).Format(wxLog::GetTimestamp()); - str += wxS(": "); -#endif // wxUSE_DATETIME + wxLog::TimeStampMS(&str, msec); return str; } @@ -743,6 +740,15 @@ void wxLog::TimeStamp(wxString *str, time_t t) } } +void wxLog::TimeStampMS(wxString *str, wxLongLong_t msec) +{ + if ( !ms_timestamp.empty() ) + { + *str = wxDateTime(wxLongLong(msec)).Format(wxLog::GetTimestamp()); + *str += wxS(": "); + } +} + #else // !wxUSE_DATETIME void wxLog::TimeStamp(wxString*) @@ -753,6 +759,10 @@ void wxLog::TimeStamp(wxString*, time_t) { } +void wxLog::TimeStampMS(wxString*, wxLongLong_t) +{ +} + #endif // wxUSE_DATETIME/!wxUSE_DATETIME #if wxUSE_THREADS