Skip to content

Commit

Permalink
fix PyQgsLogger test (fixes b5f6d2c, but also the failure on windows)
Browse files Browse the repository at this point in the history
  • Loading branch information
jef-n committed Nov 12, 2014
1 parent a036627 commit c18cb33
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 25 deletions.
46 changes: 24 additions & 22 deletions src/core/qgslogger.cpp
Expand Up @@ -37,19 +37,20 @@ QTime QgsLogger::sTime;


void QgsLogger::init() void QgsLogger::init()
{ {
if( sDebugLevel != -999 ) if ( sDebugLevel != -999 )
return; return;


sTime.start(); sTime.start();


sLogFile = getenv( "QGIS_LOG_FILE" ) ? getenv( "QGIS_LOG_FILE" ) : "";
sFileFilter = getenv( "QGIS_DEBUG_FILE" ) ? getenv( "QGIS_DEBUG_FILE" ) : ""; sFileFilter = getenv( "QGIS_DEBUG_FILE" ) ? getenv( "QGIS_DEBUG_FILE" ) : "";
sDebugLevel = getenv( "QGIS_DEBUG" ) ? atoi( getenv( "QGIS_DEBUG" ) ) : sDebugLevel = getenv( "QGIS_DEBUG" ) ? atoi( getenv( "QGIS_DEBUG" ) ) :
#ifdef QGISDEBUG #ifdef QGISDEBUG
1 1
#else #else
0 0
#endif #endif
; ;


sPrefixLength = sizeof( CMAKE_SOURCE_DIR ); sPrefixLength = sizeof( CMAKE_SOURCE_DIR );
if ( CMAKE_SOURCE_DIR[sPrefixLength-1] == '/' ) if ( CMAKE_SOURCE_DIR[sPrefixLength-1] == '/' )
Expand All @@ -66,36 +67,37 @@ void QgsLogger::debug( const QString& msg, int debuglevel, const char* file, con
if ( sDebugLevel == 0 || debuglevel > sDebugLevel ) if ( sDebugLevel == 0 || debuglevel > sDebugLevel )
return; return;



QString m = msg; 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() ) ); m.prepend( QString( "[%1ms] " ).arg( sTime.elapsed() ) );
sTime.restart(); sTime.restart();


if ( function ) if ( function )
{ {
m.prepend( QString( " (%1) " ).arg( function ) ); m.prepend( QString( " (%1) " ).arg( function ) );
} }


if ( file ) if ( line != -1 )
{ {
if( line != -1 )
{
#ifndef _MSC_VER #ifndef _MSC_VER
m.prepend( QString( ": %1:" ).arg( line ) ); m.prepend( QString( ": %1:" ).arg( line ) );
#else #else
m.prepend( QString( "(%1) :" ).arg( line ) ); m.prepend( QString( "(%1) :" ).arg( line ) );
#endif #endif
} }


#ifndef _MSC_VER #ifndef _MSC_VER
m.prepend( file + sPrefixLength ); m.prepend( file + sPrefixLength );
#else #else
m.prepend( file ); m.prepend( file );
#endif #endif
} }


Expand Down
8 changes: 5 additions & 3 deletions tests/src/python/test_qgslogger.py
Expand Up @@ -14,6 +14,11 @@


import tempfile import tempfile
import os import os

(myFileHandle, myFilename) = tempfile.mkstemp()
os.environ['QGIS_DEBUG'] = '2'
os.environ['QGIS_LOG_FILE'] = myFilename

import qgis import qgis
from qgis.core import QgsLogger from qgis.core import QgsLogger
from utilities import (TestCase, from utilities import (TestCase,
Expand All @@ -28,13 +33,10 @@
class TestQgsLogger(TestCase): class TestQgsLogger(TestCase):


def testLogger(self): def testLogger(self):
(myFileHandle, myFilename) = tempfile.mkstemp()
try: try:
myFile = os.fdopen(myFileHandle, "w") myFile = os.fdopen(myFileHandle, "w")
myFile.write("QGIS Logger Unit Test\n") myFile.write("QGIS Logger Unit Test\n")
myFile.close() myFile.close()
os.environ['QGIS_DEBUG'] = '2'
os.environ['QGIS_LOG_FILE'] = myFilename
myLogger = QgsLogger() myLogger = QgsLogger()
myLogger.debug('This is a debug') myLogger.debug('This is a debug')
myLogger.warning('This is a warning') myLogger.warning('This is a warning')
Expand Down

0 comments on commit c18cb33

Please sign in to comment.