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.
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user