Skip to content
Permalink
Browse files
strip toplevel directory from debugging output
  • Loading branch information
jef-n committed Jan 8, 2012
1 parent f08ffc6 commit 7b85948fa2a2c97afe1cbb3a902ace19e3102594
Showing with 49 additions and 34 deletions.
  1. +1 −0 cmake_templates/qgsconfig.h.in
  2. +43 −30 src/core/qgslogger.cpp
  3. +5 −4 src/core/qgslogger.h
@@ -25,6 +25,7 @@
#define QGIS_LIBEXEC_SUBDIR "${QGIS_LIBEXEC_SUBDIR}"
#define QGIS_LIB_SUBDIR "${QGIS_LIB_SUBDIR}"
#define CMAKE_INSTALL_PREFIX "${CMAKE_INSTALL_PREFIX}"
#define CMAKE_SOURCE_DIR "${CMAKE_SOURCE_DIR}"

#cmakedefine HAVE_POSTGRESQL

@@ -17,10 +17,18 @@


#include "qgslogger.h"

#include <QtDebug>
#include <QFile>

int QgsLogger::mDebugLevel = -999; // undefined value
#include "qgsconfig.h"

#ifndef CMAKE_SOURCE_DIR
#error CMAKE_SOURCE_DIR undefinied
#endif // CMAKE_SOURCE_DIR

int QgsLogger::sDebugLevel = -999; // undefined value
int QgsLogger::sPrefixLength = -1;

void QgsLogger::debug( const QString& msg, int debuglevel, const char* file, const char* function, int line )
{
@@ -44,18 +52,18 @@ void QgsLogger::debug( const QString& msg, int debuglevel, const char* file, con
}
else if ( !function )
{
m = QString( "%1: %2" ).arg( file ).arg( msg );
m = QString( "%1: %2" ).arg( file + sPrefixLength ).arg( msg );
}
else if ( line == -1 )
{
m = QString( "%1: (%2) %3" ).arg( file ).arg( function ).arg( msg );
m = QString( "%1: (%2) %3" ).arg( file + sPrefixLength ).arg( function ).arg( msg );
}
else
{
#ifndef _MSC_VER
m = QString( "%1: %2: (%3) %4" ).arg( file ).arg( line ).arg( function ).arg( msg );
m = QString( "%1: %2: (%3) %4" ).arg( file + sPrefixLength ).arg( line ).arg( function ).arg( msg );
#else
m = QString( "%1(%2) : (%3) %4" ).arg( file ).arg( line ).arg( function ).arg( msg );
m = QString( "%1(%2) : (%3) %4" ).arg( file + sPrefixLength ).arg( line ).arg( function ).arg( msg );
#endif
}
if ( logFile().isEmpty() )
@@ -83,29 +91,29 @@ void QgsLogger::debug( const QString& var, int val, int debuglevel, const char*
int dlevel = debugLevel();
if ( dlevel >= debuglevel && debuglevel > 0 )
{
if ( file == NULL )
if ( !file )
{
qDebug( "%s: %d", var.toLocal8Bit().constData(), val );
logMessageToFile( QString( "%s: %d" ).arg( var.toLocal8Bit().constData() ).arg( val ) );
}
else if ( function == NULL )
else if ( !function )
{
qDebug( "%s: %s: %d", file, var.toLocal8Bit().constData(), val );
logMessageToFile( QString( "%s: %s: %d" ).arg( file ).arg( var.toLocal8Bit().constData() ).arg( val ) );
qDebug( "%s: %s: %d", file + sPrefixLength, var.toLocal8Bit().constData(), val );
logMessageToFile( QString( "%s: %s: %d" ).arg( file + sPrefixLength ).arg( var.toLocal8Bit().constData() ).arg( val ) );
}
else if ( line == -1 )
{
qDebug( "%s: (%s): %s: %d", file, function, var.toLocal8Bit().constData(), val );
logMessageToFile( QString( "%s: (%s): %s: %d" ).arg( file ).arg( function ).arg( var.toLocal8Bit().constData() ).arg( val ) );
qDebug( "%s: (%s): %s: %d", file + sPrefixLength, function, var.toLocal8Bit().constData(), val );
logMessageToFile( QString( "%s: (%s): %s: %d" ).arg( file + sPrefixLength ).arg( function ).arg( var.toLocal8Bit().constData() ).arg( val ) );
}
else
{
#ifdef _MSC_VER
qDebug( "%s(%d): (%s), %s: %d", file, line, function, var.toLocal8Bit().constData(), val );
qDebug( "%s(%d): (%s), %s: %d", file + sPrefixLength, line, function, var.toLocal8Bit().constData(), val );
#else
qDebug( "%s: %d: (%s), %s: %d", file, line, function, var.toLocal8Bit().constData(), val );
qDebug( "%s: %d: (%s), %s: %d", file + sPrefixLength, line, function, var.toLocal8Bit().constData(), val );
#endif
logMessageToFile( QString( "%s: %d: (%s), %s: %d" ).arg( file ).arg( line ).arg( function ).arg( var.toLocal8Bit().constData() ).arg( val ) );
logMessageToFile( QString( "%s: %d: (%s), %s: %d" ).arg( file + sPrefixLength ).arg( line ).arg( function ).arg( var.toLocal8Bit().constData() ).arg( val ) );
}
}
}
@@ -124,29 +132,29 @@ void QgsLogger::debug( const QString& var, double val, int debuglevel, const cha
int dlevel = debugLevel();
if ( dlevel >= debuglevel && debuglevel > 0 )
{
if ( file == NULL )
if ( !file )
{
qDebug( "%s: %f", var.toLocal8Bit().constData(), val );
logMessageToFile( QString( "%s: %f" ).arg( var.toLocal8Bit().constData() ).arg( val ) );
}
else if ( function == NULL )
else if ( !function )
{
qDebug( "%s: %s: %f", file, var.toLocal8Bit().constData(), val );
logMessageToFile( QString( "%s: %s: %f" ).arg( file ).arg( var.toLocal8Bit().constData() ).arg( val ) );
qDebug( "%s: %s: %f", file + sPrefixLength, var.toLocal8Bit().constData(), val );
logMessageToFile( QString( "%s: %s: %f" ).arg( file + sPrefixLength ).arg( var.toLocal8Bit().constData() ).arg( val ) );
}
else if ( line == -1 )
{
qDebug( "%s: (%s): %s: %f", file, function, var.toLocal8Bit().constData(), val );
logMessageToFile( QString( "%s: (%s): %s: %f" ).arg( file ).arg( function ).arg( var.toLocal8Bit().constData() ).arg( val ) );
qDebug( "%s: (%s): %s: %f", file + sPrefixLength, function, var.toLocal8Bit().constData(), val );
logMessageToFile( QString( "%s: (%s): %s: %f" ).arg( file + sPrefixLength ).arg( function ).arg( var.toLocal8Bit().constData() ).arg( val ) );
}
else
{
#ifdef _MSC_VER
qDebug( "%s(%d): (%s), %s: %f", file, line, function, var.toLocal8Bit().constData(), val );
qDebug( "%s(%d): (%s), %s: %f", file + sPrefixLength, line, function, var.toLocal8Bit().constData(), val );
#else
qDebug( "%s: %d: (%s), %s: %f", file, line, function, var.toLocal8Bit().constData(), val );
qDebug( "%s: %d: (%s), %s: %f", file + sPrefixLength, line, function, var.toLocal8Bit().constData(), val );
#endif
logMessageToFile( QString( "%s: %d: (%s), %s: %f" ).arg( file ).arg( line ).arg( function ).arg( var.toLocal8Bit().constData() ).arg( val ) );
logMessageToFile( QString( "%s: %d: (%s), %s: %f" ).arg( file + sPrefixLength ).arg( line ).arg( function ).arg( var.toLocal8Bit().constData() ).arg( val ) );
}
}
}
@@ -171,7 +179,12 @@ void QgsLogger::fatal( const QString& msg )

int QgsLogger::debugLevel()
{
if ( mDebugLevel == -999 )
if ( sPrefixLength == -1 )
{
sPrefixLength = strlen( CMAKE_SOURCE_DIR ) + 1;
}

if ( sDebugLevel == -999 )
{
// read the environment variable QGIS_DEBUG just once,
// then reuse the value
@@ -180,24 +193,24 @@ int QgsLogger::debugLevel()
if ( dlevel == NULL ) //environment variable not set
{
#ifdef QGISDEBUG
mDebugLevel = 1; //1 is default value in debug mode
sDebugLevel = 1; //1 is default value in debug mode
#else
mDebugLevel = 0;
sDebugLevel = 0;
#endif
}
else
{
mDebugLevel = atoi( dlevel );
sDebugLevel = atoi( dlevel );
#ifdef QGISDEBUG
if ( mDebugLevel == 0 )
if ( sDebugLevel == 0 )
{
mDebugLevel = 1;
sDebugLevel = 1;
}
#endif
}
}

return mDebugLevel;
return sDebugLevel;
}

const QString QgsLogger::logFile()
@@ -86,14 +86,14 @@ class CORE_EXPORT QgsLogger
os << var.toLocal8Bit().data() << " = " << val;
if ( line == -1 )
{
qDebug( "%s: (%s) %s", file, function, os.str().c_str() );
qDebug( "%s: (%s) %s", file + sPrefixLength, function, os.str().c_str() );
}
else
{
#if defined(_MSC_VER)
qDebug( "%s(%d): (%s) %s", file, line, function, os.str().c_str() );
qDebug( "%s(%d): (%s) %s", file + sPrefixLength, line, function, os.str().c_str() );
#else
qDebug( "%s: %d: (%s) %s", file, line, function, os.str().c_str() );
qDebug( "%s: %d: (%s) %s", file + sPrefixLength, line, function, os.str().c_str() );
#endif
}
}
@@ -124,7 +124,8 @@ class CORE_EXPORT QgsLogger
static const char* debugFile();

/** current debug level */
static int mDebugLevel;
static int sDebugLevel;
static int sPrefixLength;
};

#endif

0 comments on commit 7b85948

Please sign in to comment.