diff --git a/simgear/debug/debug_types.h b/simgear/debug/debug_types.h index ed5ee894..2443276b 100644 --- a/simgear/debug/debug_types.h +++ b/simgear/debug/debug_types.h @@ -42,6 +42,10 @@ typedef enum { /** * Define the possible logging priorities (and their order). + * + * Caution - unfortunately, this enum is exposed to Nasal via the logprint() + * function as an integer parameter. Therefore, new values should only be + * appended, or the priority Nasal reports to compiled code will change. */ typedef enum { SG_BULK = 1, // For frequent messages @@ -49,8 +53,11 @@ typedef enum { SG_INFO, // Informatory messages SG_WARN, // Possible impending problem SG_ALERT, // Very possible impending problem - SG_POPUP // Severe enough to alert using a pop-up window + SG_POPUP, // Severe enough to alert using a pop-up window // SG_EXIT, // Problem (no core) // SG_ABORT // Abandon ship (core) + + SG_DEV_WARN, // Warning for developers, translated to other priority + SG_DEV_ALERT // Alert for developers, translated } sgDebugPriority; diff --git a/simgear/debug/logstream.cxx b/simgear/debug/logstream.cxx index e8766c6d..4967422c 100644 --- a/simgear/debug/logstream.cxx +++ b/simgear/debug/logstream.cxx @@ -359,6 +359,7 @@ public: bool m_stderr_isRedirectedAlready = false; bool m_stdout_isRedirectedAlready = false; #endif + bool m_developerMode = false; void startLog() { @@ -452,6 +453,7 @@ public: bool would_log( sgDebugClass c, sgDebugPriority p ) const { + p = translatePriority(p); if (p >= SG_INFO) return true; return ((c & m_logClass) != 0 && p >= m_logPriority); } @@ -459,9 +461,23 @@ public: void log( sgDebugClass c, sgDebugPriority p, const char* fileName, int line, const std::string& msg) { + p = translatePriority(p); LogEntry entry(c, p, fileName, line, msg); m_entries.push(entry); } + + sgDebugPriority translatePriority(sgDebugPriority in) const + { + if (in == SG_DEV_WARN) { + return m_developerMode ? SG_WARN : SG_DEBUG; + } + + if (in == SG_DEV_ALERT) { + return m_developerMode ? SG_POPUP : SG_WARN; + } + + return in; + } }; ///////////////////////////////////////////////////////////////////////////// @@ -489,6 +505,12 @@ logstream::setLogLevels( sgDebugClass c, sgDebugPriority p ) global_privateLogstream->setLogLevels(c, p); } +void logstream::setDeveloperMode(bool devMode) +{ + global_privateLogstream->m_developerMode = devMode; +} + + void logstream::addCallback(simgear::LogCallback* cb) { diff --git a/simgear/debug/logstream.hxx b/simgear/debug/logstream.hxx index 2f7c1ccf..e77ea330 100644 --- a/simgear/debug/logstream.hxx +++ b/simgear/debug/logstream.hxx @@ -93,6 +93,13 @@ public: sgDebugPriority get_log_priority() const; + /** + * set developer mode on/off. In developer mode, SG_DEV_WARN messags + * are treated as warnings. In normal (non-developer) mode they are + * treated as SG_DEBUG. + */ + void setDeveloperMode(bool devMode); + /** * the core logging method */