From c18cb33ae65c816dd8aa88a45556e6163a1ff24c Mon Sep 17 00:00:00 2001 From: "Juergen E. Fischer" Date: Wed, 12 Nov 2014 20:43:28 +0100 Subject: [PATCH] fix PyQgsLogger test (fixes b5f6d2ce, but also the failure on windows) --- src/core/qgslogger.cpp | 46 ++++++++++++++++-------------- tests/src/python/test_qgslogger.py | 8 ++++-- 2 files changed, 29 insertions(+), 25 deletions(-) diff --git a/src/core/qgslogger.cpp b/src/core/qgslogger.cpp index e4d7f07d1c5b..3e72fe7e2b21 100644 --- a/src/core/qgslogger.cpp +++ b/src/core/qgslogger.cpp @@ -37,19 +37,20 @@ QTime QgsLogger::sTime; void QgsLogger::init() { - if( sDebugLevel != -999 ) + if ( sDebugLevel != -999 ) return; sTime.start(); + sLogFile = getenv( "QGIS_LOG_FILE" ) ? getenv( "QGIS_LOG_FILE" ) : ""; sFileFilter = getenv( "QGIS_DEBUG_FILE" ) ? getenv( "QGIS_DEBUG_FILE" ) : ""; sDebugLevel = getenv( "QGIS_DEBUG" ) ? atoi( getenv( "QGIS_DEBUG" ) ) : #ifdef QGISDEBUG - 1 + 1 #else - 0 + 0 #endif -; + ; sPrefixLength = sizeof( CMAKE_SOURCE_DIR ); if ( CMAKE_SOURCE_DIR[sPrefixLength-1] == '/' ) @@ -66,36 +67,37 @@ void QgsLogger::debug( const QString& msg, int debuglevel, const char* file, con if ( sDebugLevel == 0 || debuglevel > sDebugLevel ) return; + QString m = msg; - if ( qApp && qApp->thread() != QThread::currentThread() ) + if ( file ) { - m.prepend( QString( "[thread:0x%1] " ).arg( (qint64) QThread::currentThread(), 0, 16 ) ); - } + if ( qApp && qApp->thread() != QThread::currentThread() ) + { + m.prepend( QString( "[thread:0x%1] " ).arg(( qint64 ) QThread::currentThread(), 0, 16 ) ); + } - m.prepend( QString( "[%1ms] " ).arg( sTime.elapsed() ) ); - sTime.restart(); + m.prepend( QString( "[%1ms] " ).arg( sTime.elapsed() ) ); + sTime.restart(); - if ( function ) - { - m.prepend( QString( " (%1) " ).arg( function ) ); - } + if ( function ) + { + m.prepend( QString( " (%1) " ).arg( function ) ); + } - if ( file ) - { - if( line != -1 ) - { + if ( line != -1 ) + { #ifndef _MSC_VER - m.prepend( QString( ": %1:" ).arg( line ) ); + m.prepend( QString( ": %1:" ).arg( line ) ); #else - m.prepend( QString( "(%1) :" ).arg( line ) ); + m.prepend( QString( "(%1) :" ).arg( line ) ); #endif - } + } #ifndef _MSC_VER - m.prepend( file + sPrefixLength ); + m.prepend( file + sPrefixLength ); #else - m.prepend( file ); + m.prepend( file ); #endif } diff --git a/tests/src/python/test_qgslogger.py b/tests/src/python/test_qgslogger.py index 16274d97c434..d1b10d79b08e 100644 --- a/tests/src/python/test_qgslogger.py +++ b/tests/src/python/test_qgslogger.py @@ -14,6 +14,11 @@ import tempfile import os + +(myFileHandle, myFilename) = tempfile.mkstemp() +os.environ['QGIS_DEBUG'] = '2' +os.environ['QGIS_LOG_FILE'] = myFilename + import qgis from qgis.core import QgsLogger from utilities import (TestCase, @@ -28,13 +33,10 @@ class TestQgsLogger(TestCase): def testLogger(self): - (myFileHandle, myFilename) = tempfile.mkstemp() try: myFile = os.fdopen(myFileHandle, "w") myFile.write("QGIS Logger Unit Test\n") myFile.close() - os.environ['QGIS_DEBUG'] = '2' - os.environ['QGIS_LOG_FILE'] = myFilename myLogger = QgsLogger() myLogger.debug('This is a debug') myLogger.warning('This is a warning')