diff --git a/docs/doxygen/overviews/envvars.h b/docs/doxygen/overviews/envvars.h index b03483f76b..051f1dfec3 100644 --- a/docs/doxygen/overviews/envvars.h +++ b/docs/doxygen/overviews/envvars.h @@ -13,6 +13,14 @@ This section describes all environment variables that affect execution of wxWidgets programs. @beginDefList +@itemdef{WXLOG_TIME_FORMAT, + If set, the contents of this variable is set as the initial timestamp + used for logging, i.e. passed to wxLog::SetTimestamp(), on program + startup. For example, this can be used to enable milliseconds in the + timestamps by setting `WXLOG_TIME_FORMAT=%H:%M:%S.%l` or it could also + be used to use ISO 8601 timestamp format instead of the default + locale-dependent format. This variable is only used since wxWidgets + 3.3.0.} @itemdef{WXTRACE, This variable can be set to a comma-separated list of trace masks used in wxLogTrace calls; wxLog::AddTraceMask is called for every mask diff --git a/interface/wx/log.h b/interface/wx/log.h index 49b4131abb..b20e154ec6 100644 --- a/interface/wx/log.h +++ b/interface/wx/log.h @@ -512,6 +512,11 @@ public: formatter and custom formatters may ignore this format. You can also define a custom wxLogFormatter to customize the time stamp handling beyond changing its format. + + In addition to calling this function explicitly, it can also be called + implicitly by wxWidgets if `WXLOG_TIME_FORMAT` environment variable is + set, see @ref overview_envvars "overview of the environment variables" + affecting wxWidgets programs. */ static void SetTimestamp(const wxString& format); diff --git a/src/common/appbase.cpp b/src/common/appbase.cpp index e4e15eab5e..406c336ef5 100644 --- a/src/common/appbase.cpp +++ b/src/common/appbase.cpp @@ -1240,6 +1240,10 @@ static void LINKAGEMODE SetTraceMasks() while ( tkn.HasMoreTokens() ) wxLog::AddTraceMask(tkn.GetNextToken()); } + + wxString ts; + if ( wxGetEnv("WXLOG_TIME_FORMAT", &ts) ) + wxLog::SetTimestamp(ts); #endif // wxUSE_LOG }