mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-14 00:07:35 -04:00
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
This commit is contained in:
parent
b44dfc1b47
commit
1e48c18c9e
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user