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()
{
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] == '/' )
Expand All @@ -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
}

Expand Down
8 changes: 5 additions & 3 deletions tests/src/python/test_qgslogger.py
Expand Up @@ -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,
Expand All @@ -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')
Expand Down

0 comments on commit c18cb33

Please sign in to comment.