[QGIS Commit] r15364 - trunk/qgis/src/core

svn_qgis at osgeo.org svn_qgis at osgeo.org
Sun Mar 6 11:17:03 EST 2011


Author: wonder
Date: 2011-03-06 08:17:03 -0800 (Sun, 06 Mar 2011)
New Revision: 15364

Modified:
   trunk/qgis/src/core/qgslogger.cpp
   trunk/qgis/src/core/qgslogger.h
Log:
Logger updates:
- evaluate QGIS_DEBUG environment variable just once
- QgsDebugMsgLevel macro will evaluate the passed string only when it will really print it.


Modified: trunk/qgis/src/core/qgslogger.cpp
===================================================================
--- trunk/qgis/src/core/qgslogger.cpp	2011-03-06 16:02:01 UTC (rev 15363)
+++ trunk/qgis/src/core/qgslogger.cpp	2011-03-06 16:17:03 UTC (rev 15364)
@@ -19,6 +19,8 @@
 #include "qgslogger.h"
 #include <QtDebug>
 
+int QgsLogger::mDebugLevel = -999; // undefined value
+
 void QgsLogger::debug( const QString& msg, int debuglevel, const char* file, const char* function, int line )
 {
   const char* dfile = debugFile();
@@ -147,23 +149,33 @@
 
 int QgsLogger::debugLevel()
 {
-  const char* dlevel = getenv( "QGIS_DEBUG" );
-  if ( dlevel == NULL ) //environment variable not set
+  if ( mDebugLevel == -999 )
   {
+    // read the environment variable QGIS_DEBUG just once,
+    // then reuse the value
+
+    const char* dlevel = getenv( "QGIS_DEBUG" );
+    if ( dlevel == NULL ) //environment variable not set
+    {
 #ifdef QGISDEBUG
-    return 1; //1 is default value in debug mode
+      mDebugLevel = 1; //1 is default value in debug mode
 #else
-    return 0;
+      mDebugLevel = 0;
 #endif
-  }
-  int level = atoi( dlevel );
+    }
+    else
+    {
+      mDebugLevel = atoi( dlevel );
 #ifdef QGISDEBUG
-  if ( level == 0 )
-  {
-    level = 1;
+      if ( mDebugLevel == 0 )
+      {
+        mDebugLevel = 1;
+      }
+#endif
+    }
   }
-#endif
-  return level;
+
+  return mDebugLevel;
 }
 
 const char* QgsLogger::debugFile()

Modified: trunk/qgis/src/core/qgslogger.h
===================================================================
--- trunk/qgis/src/core/qgslogger.h	2011-03-06 16:02:01 UTC (rev 15363)
+++ trunk/qgis/src/core/qgslogger.h	2011-03-06 16:17:03 UTC (rev 15364)
@@ -24,8 +24,11 @@
 
 #ifdef QGISDEBUG
 #define QgsDebugMsg(str) QgsLogger::debug(QString(str), 1, __FILE__, __FUNCTION__, __LINE__)
-#define QgsDebugMsgLevel(str, level) QgsLogger::debug(QString(str), level,\
-    __FILE__, __FUNCTION__, __LINE__)
+#define QgsDebugMsgLevel(str, level) \
+  { \
+    if ( QgsLogger::debugLevel() >= (level) && (level) > 0 ) \
+      QgsLogger::debug(QString(str), (level), __FILE__, __FUNCTION__, __LINE__); \
+  }
 #else
 #define QgsDebugMsg(str)
 #define QgsDebugMsgLevel(str, level)
@@ -99,13 +102,17 @@
     /**Goes to qFatal*/
     static void fatal( const QString& msg );
 
-  private:
     /**Reads the environment variable QGIS_DEBUG and converts it to int. If QGIS_DEBUG is not set,
      the function returns 1 if QGISDEBUG is defined and 0 if not*/
     static int debugLevel();
 
+  private:
+
     /**Reads the environment variable QGIS_DEBUG_FILE. Returns NULL if the variable is not set*/
     static const char* debugFile();
+
+    /** current debug level */
+    static int mDebugLevel;
 };
 
 #endif



More information about the QGIS-commit mailing list