X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=simgear%2Fdebug%2Flogstream.hxx;h=d3649a4a21b3cf5912dd20778d9daf39abb37b5b;hb=10217a3b19f690624e42b224a6fb08b6673c3edd;hp=c79f7766f805d3e3388a0e8c7dea038ae389ce95;hpb=d4c7e950927b1e19a7a7622a7919f32233a6b7a8;p=simgear.git diff --git a/simgear/debug/logstream.hxx b/simgear/debug/logstream.hxx index c79f7766..d3649a4a 100644 --- a/simgear/debug/logstream.hxx +++ b/simgear/debug/logstream.hxx @@ -27,12 +27,13 @@ #include -#ifdef _MSC_VER +#ifdef _WIN32 # include #endif #include #include +#include #include @@ -78,6 +79,8 @@ public: */ void set_log_state( sgDebugClass c, sgDebugPriority p ); + bool would_log( sgDebugClass c, sgDebugPriority p ) const; + /** * Set the global logging level. * @param c debug class @@ -120,7 +123,7 @@ public: */ void set_sb( std::streambuf* sb ); -#ifdef _MSC_VER +#ifdef _WIN32 static void has_no_console() { has_console = false; } #endif @@ -139,7 +142,7 @@ private: static std::streambuf* sbuf; static bool logging_enabled; -#ifdef _MSC_VER +#ifdef _WIN32 static bool has_console; #endif static sgDebugClass logClass; @@ -164,10 +167,16 @@ logbuf::set_log_state( sgDebugClass c, sgDebugPriority p ) logging_enabled = ((c & logClass) != 0 && p >= logPriority); } +inline bool +logbuf::would_log( sgDebugClass c, sgDebugPriority p ) const +{ + return ((c & logClass) != 0 && p >= logPriority); +} + inline logbuf::int_type logbuf::overflow( int c ) { -#ifdef _MSC_VER +#ifdef _WIN32 if ( logging_enabled ) { if ( !has_console ) { AllocConsole(); @@ -240,15 +249,20 @@ public: */ void setLogLevels( sgDebugClass c, sgDebugPriority p ); + bool would_log( sgDebugClass c, sgDebugPriority p ) const + { + return lbuf.would_log( c, p ); + }; + /** * Output operator to capture the debug level and priority of a message. * @param l log level */ inline std::ostream& operator<< ( const loglevel& l ); friend logstream& sglog(); + static logstream *initGlobalLogstream(); protected: static logstream *global_logstream; - static void initGlobalLogstream(); }; inline std::ostream& @@ -268,10 +282,7 @@ logstream::operator<< ( const loglevel& l ) inline logstream& sglog() { - if (logstream::global_logstream == NULL) { - logstream::initGlobalLogstream(); - } - return *logstream::global_logstream; + return *logstream::initGlobalLogstream(); } @@ -284,7 +295,11 @@ sglog() #ifdef FG_NDEBUG # define SG_LOG(C,P,M) #else -# define SG_LOG(C,P,M) sglog() << loglevel(C,P) << M << std::endl +# define SG_LOG(C,P,M) do { \ + logstream& __tmplogstreamref(sglog()); \ + if(__tmplogstreamref.would_log(C,P)) { \ + __tmplogstreamref << loglevel(C,P) << M << std::endl; } \ + } while(0) #endif #define SG_ORIGIN __FILE__ ":" SG_STRINGIZE(__LINE__)