diff --git a/simgear/debug/logstream.cxx b/simgear/debug/logstream.cxx index a7d69ff7..b8b4d312 100644 --- a/simgear/debug/logstream.cxx +++ b/simgear/debug/logstream.cxx @@ -335,9 +335,7 @@ public: ~LogStreamPrivate() { - for (simgear::LogCallback* cb : m_callbacks) { - delete cb; - } + removeCallbacks(); } SGMutex m_lock; @@ -363,6 +361,9 @@ public: #endif bool m_developerMode = false; + // test suite mode. + bool m_testMode = false; + void startLog() { SGGuard g(m_lock); @@ -443,6 +444,16 @@ public: } } + void removeCallbacks() + { + PauseThread pause(this); + for (simgear::LogCallback* cb : m_callbacks) { + delete cb; + } + m_callbacks.clear(); + m_consoleCallbacks.clear(); + } + void setLogLevels( sgDebugClass c, sgDebugPriority p ) { PauseThread pause(this); @@ -455,6 +466,9 @@ public: bool would_log( sgDebugClass c, sgDebugPriority p ) const { + // Testing mode, so always log. + if (m_testMode) return true; + p = translatePriority(p); if (p >= SG_INFO) return true; return ((c & m_logClass) != 0 && p >= m_logPriority); @@ -711,6 +725,13 @@ void logstream::requestConsole() #endif } +void +logstream::setTestingMode( bool testMode ) +{ + d->m_testMode = testMode; + if (testMode) d->removeCallbacks(); +} + namespace simgear { diff --git a/simgear/debug/logstream.hxx b/simgear/debug/logstream.hxx index 32e19e95..6d951d4c 100644 --- a/simgear/debug/logstream.hxx +++ b/simgear/debug/logstream.hxx @@ -158,12 +158,22 @@ public: void removeCallback(simgear::LogCallback* cb); + void removeCallbacks(); + /** * optionally record all entries and submit them to new log callbacks that * are added. This allows simplified logging configuration, but still including * early startup information in all logs. */ void setStartupLoggingEnabled(bool enabled); + + /** + * Set up the logstream for running in test mode. For example the callbacks + * will be unregistered and the behaviour of the would_log() function + * sanitized. + */ + void setTestingMode(bool testMode); + private: // constructor logstream();