LogStream: Added a testing mode to the simgear logstreams.

The new function logstream::setTestingMode() has been created to allow for a
testing mode to be set.  This stores a boolean in the private logstream thread
which modifies the behaviour of the would_log() function, allowing for
everything to be logged.  The removeCallbacks() function has also been added,
allowing for the default fgfs output to STDOUT and STDERR to be silenced when
calling setTestingMode().
This commit is contained in:
Edward d'Auvergne
2018-02-28 12:08:25 +01:00
committed by James Turner
parent 62ae6ca35e
commit 340a469153
2 changed files with 34 additions and 3 deletions

View File

@@ -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<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 )
{
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
{

View File

@@ -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();