Skip to content

Commit c18cb33

Browse files
committedNov 12, 2014
fix PyQgsLogger test (fixes b5f6d2c, but also the failure on windows)
1 parent a036627 commit c18cb33

File tree

2 files changed

+29
-25
lines changed

2 files changed

+29
-25
lines changed
 

‎src/core/qgslogger.cpp

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -37,19 +37,20 @@ QTime QgsLogger::sTime;
3737

3838
void QgsLogger::init()
3939
{
40-
if( sDebugLevel != -999 )
40+
if ( sDebugLevel != -999 )
4141
return;
4242

4343
sTime.start();
4444

45+
sLogFile = getenv( "QGIS_LOG_FILE" ) ? getenv( "QGIS_LOG_FILE" ) : "";
4546
sFileFilter = getenv( "QGIS_DEBUG_FILE" ) ? getenv( "QGIS_DEBUG_FILE" ) : "";
4647
sDebugLevel = getenv( "QGIS_DEBUG" ) ? atoi( getenv( "QGIS_DEBUG" ) ) :
4748
#ifdef QGISDEBUG
48-
1
49+
1
4950
#else
50-
0
51+
0
5152
#endif
52-
;
53+
;
5354

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

70+
6971
QString m = msg;
7072

71-
if ( qApp && qApp->thread() != QThread::currentThread() )
73+
if ( file )
7274
{
73-
m.prepend( QString( "[thread:0x%1] " ).arg( (qint64) QThread::currentThread(), 0, 16 ) );
74-
}
75+
if ( qApp && qApp->thread() != QThread::currentThread() )
76+
{
77+
m.prepend( QString( "[thread:0x%1] " ).arg(( qint64 ) QThread::currentThread(), 0, 16 ) );
78+
}
7579

76-
m.prepend( QString( "[%1ms] " ).arg( sTime.elapsed() ) );
77-
sTime.restart();
80+
m.prepend( QString( "[%1ms] " ).arg( sTime.elapsed() ) );
81+
sTime.restart();
7882

79-
if ( function )
80-
{
81-
m.prepend( QString( " (%1) " ).arg( function ) );
82-
}
83+
if ( function )
84+
{
85+
m.prepend( QString( " (%1) " ).arg( function ) );
86+
}
8387

84-
if ( file )
85-
{
86-
if( line != -1 )
87-
{
88+
if ( line != -1 )
89+
{
8890
#ifndef _MSC_VER
89-
m.prepend( QString( ": %1:" ).arg( line ) );
91+
m.prepend( QString( ": %1:" ).arg( line ) );
9092
#else
91-
m.prepend( QString( "(%1) :" ).arg( line ) );
93+
m.prepend( QString( "(%1) :" ).arg( line ) );
9294
#endif
93-
}
95+
}
9496

9597
#ifndef _MSC_VER
96-
m.prepend( file + sPrefixLength );
98+
m.prepend( file + sPrefixLength );
9799
#else
98-
m.prepend( file );
100+
m.prepend( file );
99101
#endif
100102
}
101103

‎tests/src/python/test_qgslogger.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@
1414

1515
import tempfile
1616
import os
17+
18+
(myFileHandle, myFilename) = tempfile.mkstemp()
19+
os.environ['QGIS_DEBUG'] = '2'
20+
os.environ['QGIS_LOG_FILE'] = myFilename
21+
1722
import qgis
1823
from qgis.core import QgsLogger
1924
from utilities import (TestCase,
@@ -28,13 +33,10 @@
2833
class TestQgsLogger(TestCase):
2934

3035
def testLogger(self):
31-
(myFileHandle, myFilename) = tempfile.mkstemp()
3236
try:
3337
myFile = os.fdopen(myFileHandle, "w")
3438
myFile.write("QGIS Logger Unit Test\n")
3539
myFile.close()
36-
os.environ['QGIS_DEBUG'] = '2'
37-
os.environ['QGIS_LOG_FILE'] = myFilename
3840
myLogger = QgsLogger()
3941
myLogger.debug('This is a debug')
4042
myLogger.warning('This is a warning')

0 commit comments

Comments
 (0)
Please sign in to comment.