Skip to content
Permalink
Browse files

Logger updates:

- evaluate QGIS_DEBUG environment variable just once
- QgsDebugMsgLevel macro will evaluate the passed string only when it will really print it.


git-svn-id: http://svn.osgeo.org/qgis/trunk@15364 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
wonder
wonder committed Mar 6, 2011
1 parent b44dfc1 commit 1e48c18c9e3eafd4b75ed84800d7a2238dd426a3
Showing with 33 additions and 14 deletions.
  1. +23 −11 src/core/qgslogger.cpp
  2. +10 −3 src/core/qgslogger.h
@@ -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 @@ void QgsLogger::fatal( const QString& msg )

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
return level;
}
}

return mDebugLevel;
}

const char* QgsLogger::debugFile()
@@ -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 @@ class CORE_EXPORT QgsLogger
/**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

0 comments on commit 1e48c18

Please sign in to comment.
You can’t perform that action at this time.