class StderrLogCallback : public simgear::LogCallback
{
public:
- StderrLogCallback()
+ StderrLogCallback(sgDebugClass c, sgDebugPriority p) :
+ m_class(c),
+ m_priority(p)
{
#ifdef _WIN32
AllocConsole(); // but only if we want a console
freopen("conout$", "w", stderr);
#endif
}
-
+
+ void setLogLevels( sgDebugClass c, sgDebugPriority p )
+ {
+ m_priority = p;
+ m_class = c;
+ }
+
virtual void operator()(sgDebugClass c, sgDebugPriority p,
const char* file, int line, const std::string& aMessage)
{
+ if ((c & m_class) == 0 || p < m_priority) return;
+
// if running under MSVC, we could use OutputDebugString here
fprintf(stderr, "%s\n", aMessage.c_str());
fflush(stderr);
}
private:
-
+ sgDebugClass m_class;
+ sgDebugPriority m_priority;
};
namespace simgear
};
public:
LogStreamPrivate() :
- m_logClass(SG_ALL), m_logPriority(SG_WARN),
+ m_logClass(SG_ALL),
+ m_logPriority(SG_ALERT),
m_isRunning(false)
- { }
+ {
+ m_stderrCallback = new StderrLogCallback(m_logClass, m_logPriority);
+ addCallback(m_stderrCallback);
+ }
SGMutex m_lock;
SGBlockingQueue<LogEntry> m_entries;
sgDebugClass m_logClass;
sgDebugPriority m_logPriority;
bool m_isRunning;
+ StderrLogCallback* m_stderrCallback;
void startLog()
{
{
while (1) {
LogEntry entry(m_entries.pop());
+ // special marker entry detected, terminate the thread since we are
+ // making a configuration change or quitting the app
if ((entry.debugClass == SG_NONE) && !strcmp(entry.file, "done")) {
return;
}
}
}
+ void setLogLevels( sgDebugClass c, sgDebugPriority p )
+ {
+ bool wasRunning = stop();
+ m_logPriority = p;
+ m_logClass = c;
+ m_stderrCallback->setLogLevels(c, p);
+ if (wasRunning) {
+ startLog();
+ }
+ }
+
bool would_log( sgDebugClass c, sgDebugPriority p ) const
{
if (p >= SG_INFO) return true;
logstream::logstream()
{
global_privateLogstream = new LogStreamPrivate;
- global_privateLogstream->addCallback(new StderrLogCallback);
global_privateLogstream->startLog();
}
void
logstream::setLogLevels( sgDebugClass c, sgDebugPriority p )
{
- // we don't guard writing these with a mutex, since we assume setting
- // occurs very rarely, and any data races are benign.
- global_privateLogstream->m_logClass = c;
- global_privateLogstream->m_logPriority = p;
+ global_privateLogstream->setLogLevels(c, p);
}
void