diff --git a/simgear/debug/BufferedLogCallback.cxx b/simgear/debug/BufferedLogCallback.cxx index a0e63976..b5086ad5 100644 --- a/simgear/debug/BufferedLogCallback.cxx +++ b/simgear/debug/BufferedLogCallback.cxx @@ -52,11 +52,11 @@ BufferedLogCallback::BufferedLogCallback(sgDebugClass c, sgDebugPriority p) : BufferedLogCallback::~BufferedLogCallback() { - BOOST_FOREACH(unsigned char* msg, d->m_buffer) { + for (unsigned char* msg : d->m_buffer) { free(msg); } } - + void BufferedLogCallback::operator()(sgDebugClass c, sgDebugPriority p, const char* file, int line, const std::string& aMessage) { diff --git a/simgear/debug/BufferedLogCallback.hxx b/simgear/debug/BufferedLogCallback.hxx index bda7fd31..ba808cc0 100644 --- a/simgear/debug/BufferedLogCallback.hxx +++ b/simgear/debug/BufferedLogCallback.hxx @@ -41,8 +41,8 @@ public: /// for broken PUI behaviour, it can be removed once PUI is gone. void truncateAt(unsigned int); - virtual void operator()(sgDebugClass c, sgDebugPriority p, - const char* file, int line, const std::string& aMessage); + void operator()(sgDebugClass c, sgDebugPriority p, + const char* file, int line, const std::string& aMessage) override; /** * read the stamp value associated with the log buffer. This is diff --git a/simgear/debug/logstream.cxx b/simgear/debug/logstream.cxx index eeda8901..7d4c5556 100644 --- a/simgear/debug/logstream.cxx +++ b/simgear/debug/logstream.cxx @@ -398,6 +398,8 @@ public: /// and hence should dynamically reflect console logging settings CallbackVec m_consoleCallbacks; + std::vector m_popupMessages; + sgDebugClass m_logClass; sgDebugPriority m_logPriority; bool m_isRunning = false; @@ -506,25 +508,11 @@ public: PauseThread pause(this); m_logPriority = p; m_logClass = c; - BOOST_FOREACH(simgear::LogCallback* cb, m_consoleCallbacks) { + for (auto cb : m_consoleCallbacks) { cb->setLogLevels(c, p); } } - bool would_log( sgDebugClass c, sgDebugPriority p ) const - { - // Testing mode, so always log. - if (m_testMode) return true; - - // SG_OSG (OSG notify) - will always be displayed regardless of FG log settings as OSG log level is configured - // separately and thus it makes more sense to allow these message through. - if (p == SG_OSG) return true; - - p = translatePriority(p); - if (p >= SG_INFO) return true; - return ((c & m_logClass) != 0 && p >= m_logPriority); - } - void log( sgDebugClass c, sgDebugPriority p, const char* fileName, int line, const std::string& msg) { @@ -560,7 +548,6 @@ logstream::logstream() logstream::~logstream() { - popup_msgs.clear(); d->stop(); } @@ -598,6 +585,10 @@ logstream::log( sgDebugClass c, sgDebugPriority p, void logstream::hexdump(sgDebugClass c, sgDebugPriority p, const char* fileName, int line, const void *mem, unsigned int len, unsigned int columns) { + if (((c & d->m_logClass) == 0) || (p < d->m_logPriority)) { + return; + } + unsigned int i, j; char temp[3000], temp1[3000]; *temp = 0; @@ -653,17 +644,17 @@ void logstream::hexdump(sgDebugClass c, sgDebugPriority p, const char* fileName, void logstream::popup( const std::string& msg) { - popup_msgs.push_back(msg); + d->m_popupMessages.push_back(msg); } std::string logstream::get_popup() { std::string rv = ""; - if (!popup_msgs.empty()) + if (!d->m_popupMessages.empty()) { - rv = popup_msgs.front(); - popup_msgs.erase(popup_msgs.begin()); + rv = d->m_popupMessages.front(); + d->m_popupMessages.erase(d->m_popupMessages.begin()); } return rv; } @@ -671,13 +662,7 @@ logstream::get_popup() bool logstream::has_popup() { - return (popup_msgs.size() > 0) ? true : false; -} - -bool -logstream::would_log( sgDebugClass c, sgDebugPriority p ) const -{ - return d->would_log(c,p); + return !d->m_popupMessages.empty(); } sgDebugClass diff --git a/simgear/debug/logstream.hxx b/simgear/debug/logstream.hxx index 30c656c7..2f8a30af 100644 --- a/simgear/debug/logstream.hxx +++ b/simgear/debug/logstream.hxx @@ -29,7 +29,6 @@ #include #include -#include #include // forward decls @@ -93,8 +92,6 @@ public: */ void setLogLevels( sgDebugClass c, sgDebugPriority p ); - bool would_log( sgDebugClass c, sgDebugPriority p ) const; - void logToFile( const SGPath& aPath, sgDebugClass c, sgDebugPriority p ); void set_log_priority( sgDebugPriority p); @@ -179,8 +176,6 @@ private: // constructor logstream(); - std::vector popup_msgs; - class LogStreamPrivate; std::unique_ptr d; @@ -197,17 +192,17 @@ logstream& sglog(); * @param M message */ # define SG_LOGX(C,P,M) \ - do { if(sglog().would_log(C,P)) { \ + do { \ std::ostringstream os; os << M; \ sglog().log(C, P, __FILE__, __LINE__, os.str()); \ if ((P) == SG_POPUP) sglog().popup(os.str()); \ - } } while(0) + } while(0) #ifdef FG_NDEBUG # define SG_LOG(C,P,M) do { if((P) == SG_POPUP) SG_LOGX(C,P,M) } while(0) # define SG_HEXDUMP(C,P,MEM,LEN) #else # define SG_LOG(C,P,M) SG_LOGX(C,P,M) -# define SG_LOG_HEXDUMP(C,P,MEM,LEN) if(sglog().would_log(C,P)) sglog().hexdump(C, P, __FILE__, __LINE__, MEM, LEN) +# define SG_LOG_HEXDUMP(C,P,MEM,LEN) sglog().hexdump(C, P, __FILE__, __LINE__, MEM, LEN) #endif #define SG_ORIGIN __FILE__ ":" SG_STRINGIZE(__LINE__)