Concept for developer log messages.

This commit is contained in:
James Turner
2017-02-14 18:27:40 -08:00
parent e21ad4b5c1
commit f977be5fe4
3 changed files with 37 additions and 1 deletions
+8 -1
View File
@@ -42,6 +42,10 @@ typedef enum {
/** /**
* Define the possible logging priorities (and their order). * 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 { typedef enum {
SG_BULK = 1, // For frequent messages SG_BULK = 1, // For frequent messages
@@ -49,8 +53,11 @@ typedef enum {
SG_INFO, // Informatory messages SG_INFO, // Informatory messages
SG_WARN, // Possible impending problem SG_WARN, // Possible impending problem
SG_ALERT, // Very 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_EXIT, // Problem (no core)
// SG_ABORT // Abandon ship (core) // SG_ABORT // Abandon ship (core)
SG_DEV_WARN, // Warning for developers, translated to other priority
SG_DEV_ALERT // Alert for developers, translated
} sgDebugPriority; } sgDebugPriority;
+22
View File
@@ -359,6 +359,7 @@ public:
bool m_stderr_isRedirectedAlready = false; bool m_stderr_isRedirectedAlready = false;
bool m_stdout_isRedirectedAlready = false; bool m_stdout_isRedirectedAlready = false;
#endif #endif
bool m_developerMode = false;
void startLog() void startLog()
{ {
@@ -452,6 +453,7 @@ public:
bool would_log( sgDebugClass c, sgDebugPriority p ) const bool would_log( sgDebugClass c, sgDebugPriority p ) const
{ {
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);
} }
@@ -459,9 +461,23 @@ public:
void log( sgDebugClass c, sgDebugPriority p, void log( sgDebugClass c, sgDebugPriority p,
const char* fileName, int line, const std::string& msg) const char* fileName, int line, const std::string& msg)
{ {
p = translatePriority(p);
LogEntry entry(c, p, fileName, line, msg); LogEntry entry(c, p, fileName, line, msg);
m_entries.push(entry); 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); global_privateLogstream->setLogLevels(c, p);
} }
void logstream::setDeveloperMode(bool devMode)
{
global_privateLogstream->m_developerMode = devMode;
}
void void
logstream::addCallback(simgear::LogCallback* cb) logstream::addCallback(simgear::LogCallback* cb)
{ {
+7
View File
@@ -93,6 +93,13 @@ public:
sgDebugPriority get_log_priority() const; 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 * the core logging method
*/ */