This commit is contained in:
gallaert
2018-03-25 18:27:57 +01:00
2 changed files with 34 additions and 3 deletions
+24 -3
View File
@@ -335,9 +335,7 @@ public:
~LogStreamPrivate() ~LogStreamPrivate()
{ {
for (simgear::LogCallback* cb : m_callbacks) { removeCallbacks();
delete cb;
}
} }
SGMutex m_lock; SGMutex m_lock;
@@ -363,6 +361,9 @@ public:
#endif #endif
bool m_developerMode = false; bool m_developerMode = false;
// test suite mode.
bool m_testMode = false;
void startLog() void startLog()
{ {
SGGuard<SGMutex> g(m_lock); SGGuard<SGMutex> 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 ) void setLogLevels( sgDebugClass c, sgDebugPriority p )
{ {
PauseThread pause(this); PauseThread pause(this);
@@ -455,6 +466,9 @@ public:
bool would_log( sgDebugClass c, sgDebugPriority p ) const bool would_log( sgDebugClass c, sgDebugPriority p ) const
{ {
// Testing mode, so always log.
if (m_testMode) return true;
p = translatePriority(p); p = translatePriority(p);
if (p >= SG_INFO) return true; if (p >= SG_INFO) return true;
return ((c & m_logClass) != 0 && p >= m_logPriority); return ((c & m_logClass) != 0 && p >= m_logPriority);
@@ -711,6 +725,13 @@ void logstream::requestConsole()
#endif #endif
} }
void
logstream::setTestingMode( bool testMode )
{
d->m_testMode = testMode;
if (testMode) d->removeCallbacks();
}
namespace simgear namespace simgear
{ {
+10
View File
@@ -158,12 +158,22 @@ public:
void removeCallback(simgear::LogCallback* cb); void removeCallback(simgear::LogCallback* cb);
void removeCallbacks();
/** /**
* optionally record all entries and submit them to new log callbacks that * optionally record all entries and submit them to new log callbacks that
* are added. This allows simplified logging configuration, but still including * are added. This allows simplified logging configuration, but still including
* early startup information in all logs. * early startup information in all logs.
*/ */
void setStartupLoggingEnabled(bool enabled); 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: private:
// constructor // constructor
logstream(); logstream();