]> git.mxchange.org Git - simgear.git/blobdiff - simgear/debug/logstream.hxx
remove CopyPolicy from ModelRegistry
[simgear.git] / simgear / debug / logstream.hxx
index c79f7766f805d3e3388a0e8c7dea038ae389ce95..c2a5edc5b6d7110b5fc68462ae75f602c8384e78 100644 (file)
@@ -33,6 +33,7 @@
 
 #include <streambuf>
 #include <ostream>
+#include <cstdio>
 
 #include <simgear/debug/debug_types.h>
 
@@ -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
@@ -164,6 +167,12 @@ 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 )
 {
@@ -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__)