Skip to content
Permalink
Browse files

fix PyQgsLogger test (fixes b5f6d2c, but also the failure on windows)

  • Loading branch information
jef-n committed Nov 12, 2014
1 parent a036627 commit c18cb33ae65c816dd8aa88a45556e6163a1ff24c
Showing with 29 additions and 25 deletions.
  1. +24 −22 src/core/qgslogger.cpp
  2. +5 −3 tests/src/python/test_qgslogger.py
@@ -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
}

@@ -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')

0 comments on commit c18cb33

Please sign in to comment.
You can’t perform that action at this time.