// ----------------------
// these functions allow to completely disable all log messages or disable
- // log messages at level less important than specified
+ // log messages at level less important than specified for the current
+ // thread
// is logging enabled at all now?
- static bool IsEnabled() { return ms_doLog; }
+ static bool IsEnabled()
+ {
+#if wxUSE_THREADS
+ if ( !wxThread::IsMain() )
+ return IsThreadLoggingEnabled();
+#endif // wxUSE_THREADS
+
+ return ms_doLog;
+ }
// change the flag state, return the previous one
- static bool EnableLogging(bool doIt = true)
- { bool doLogOld = ms_doLog; ms_doLog = doIt; return doLogOld; }
+ static bool EnableLogging(bool enable = true)
+ {
+#if wxUSE_THREADS
+ if ( !wxThread::IsMain() )
+ return EnableThreadLogging(enable);
+#endif // wxUSE_THREADS
+ bool doLogOld = ms_doLog;
+ ms_doLog = enable;
+ return doLogOld;
+ }
// return the current global log level
static wxLogLevel GetLogLevel() { return ms_logLevel; }
// 17 modal dialogs one after another)
virtual void Flush();
- // flush the active target if any
- static void FlushActive()
- {
- if ( !ms_suspendCount )
- {
- wxLog *log = GetActiveTarget();
- if ( log )
- log->Flush();
- }
- }
+ // flush the active target if any and also output any pending messages from
+ // background threads
+ static void FlushActive();
- // only one sink is active at each moment
- // get current log target, will call wxApp::CreateLogTarget() to
- // create one if none exists
+ // only one sink is active at each moment get current log target, will call
+ // wxAppTraits::CreateLogTarget() to create one if none exists
static wxLog *GetActiveTarget();
- // change log target, pLogger may be NULL
- static wxLog *SetActiveTarget(wxLog *pLogger);
+ // change log target, logger may be NULL
+ static wxLog *SetActiveTarget(wxLog *logger);
+
+#if wxUSE_THREADS
+ // change log target for the current thread only, shouldn't be called from
+ // the main thread as it doesn't use thread-specific log target
+ static wxLog *SetThreadActiveTarget(wxLog *logger);
+#endif // wxUSE_THREADS
// suspend the message flushing of the main target until the next call
// to Resume() - this is mainly for internal use (to prevent wxYield()
unsigned LogLastRepeatIfNeeded();
private:
- // called from OnLog() if it's called from the main thread and from Flush()
+#if wxUSE_THREADS
+ // called from FlushActive() to really log any buffered messages logged
+ // from the other threads
+ void FlushThreadMessages();
+
+ // these functions are called for non-main thread only by IsEnabled() and
+ // EnableLogging() respectively
+ static bool IsThreadLoggingEnabled();
+ static bool EnableThreadLogging(bool enable = true);
+#endif // wxUSE_THREADS
+
+ // get the active log target for the main thread, auto-creating it if
+ // necessary
+ //
+ // this is called from GetActiveTarget() and OnLog() when they're called
+ // from the main thread
+ static wxLog *GetMainThreadActiveTarget();
+
+ // called from OnLog() if it's called from the main thread or if we have a
+ // (presumably MT-safe) thread-specific logger and by FlushThreadMessages()
// when it plays back the buffered messages logged from the other threads
- void OnLogInMainThread(wxLogLevel level,
- const wxString& msg,
- const wxLogRecordInfo& info);
+ void CallDoLogNow(wxLogLevel level,
+ const wxString& msg,
+ const wxLogRecordInfo& info);
// static variables