X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;ds=sidebyside;f=simgear%2Fdebug%2Flogstream.hxx;h=4e2771b9989857923be633eaf92019f3234a0a05;hb=ba83177019da0c941f55b6ef3b709ed7a57d4155;hp=0af98c6a71a7d05dc5be344d6308e7c219b8c746;hpb=318c5000ce58a07a279053f084a28faaef5c422d;p=simgear.git diff --git a/simgear/debug/logstream.hxx b/simgear/debug/logstream.hxx index 0af98c6a..4e2771b9 100644 --- a/simgear/debug/logstream.hxx +++ b/simgear/debug/logstream.hxx @@ -29,6 +29,7 @@ #include #include +#include // forward decls class SGPath; @@ -42,8 +43,26 @@ public: virtual ~LogCallback() {} virtual void operator()(sgDebugClass c, sgDebugPriority p, const char* file, int line, const std::string& aMessage) = 0; + + void setLogLevels(sgDebugClass c, sgDebugPriority p); +protected: + LogCallback(sgDebugClass c, sgDebugPriority p); + + bool shouldLog(sgDebugClass c, sgDebugPriority p) const; +private: + sgDebugClass m_class; + sgDebugPriority m_priority; }; - + +/** + * Helper force a console on platforms where it might optional, when + * we need to show a console. This basically means Windows at the + * moment - on other plaforms it's a no-op + */ +void requestConsole(); + +void shutdownLogging(); + } // of namespace simgear /** @@ -52,6 +71,8 @@ public: class logstream { public: + ~logstream(); + static void initGlobalLogstream(); /** * Set the global log class and priority level. @@ -78,6 +99,23 @@ public: void log( sgDebugClass c, sgDebugPriority p, const char* fileName, int line, const std::string& msg); + /** + * support for the SG_POPUP logging class + * set the content of the popup message + */ + void popup( const std::string& msg); + + /** + * retrieve the contents of the popup message and clear it's internal + * content. The return value may be an empty string. + */ + std::string get_popup(); + + /** + * return true if a new popup message is available. false otherwise. + */ + bool has_popup(); + /** * \relates logstream * Return the one and only logstream instance. @@ -99,26 +137,30 @@ public: private: // constructor logstream(); + + std::vector popup_msgs; }; logstream& sglog(); + + /** \def SG_LOG(C,P,M) * Log a message. * @param C debug class * @param P priority * @param M message */ +# define SG_LOGX(C,P,M) \ + do { if(sglog().would_log(C,P)) { \ + std::ostringstream os; os << M; \ + sglog().log(C, P, __FILE__, __LINE__, os.str()); \ + if (P == SG_POPUP) sglog().popup(os.str()); \ + } } while(0) #ifdef FG_NDEBUG -# define SG_LOG(C,P,M) +# define SG_LOG(C,P,M) do { if(P == SG_POPUP) SG_LOGX(C,P,M) } while(0) #else -# define SG_LOG(C,P,M) do { \ - if(sglog().would_log(C,P)) { \ - std::ostringstream os; \ - os << M; \ - sglog().log(C, P, __FILE__, __LINE__, os.str()); \ - } \ -} while(0) +# define SG_LOG(C,P,M) SG_LOGX(C,P,M) #endif #define SG_ORIGIN __FILE__ ":" SG_STRINGIZE(__LINE__)