Skip to content

Commit b1743dc

Browse files
committed
Make log messages visible in the QGIS server log file
1 parent e0bedc2 commit b1743dc

6 files changed

+97
-89
lines changed

src/server/qgshttprequesthandler.cpp

+15-14
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
#include "qgshttprequesthandler.h"
2121
#include "qgsftptransaction.h"
2222
#include "qgshttptransaction.h"
23-
#include "qgslogger.h"
23+
#include "qgsmessagelog.h"
2424
#include "qgsmapserviceexception.h"
2525
#include <QBuffer>
2626
#include <QByteArray>
@@ -47,7 +47,7 @@ QgsHttpRequestHandler::~QgsHttpRequestHandler()
4747

4848
void QgsHttpRequestHandler::setHttpResponse( QByteArray *ba, const QString &format )
4949
{
50-
QgsDebugMsg( "Checking byte array is ok to set..." );
50+
QgsMessageLog::logMessage( "Checking byte array is ok to set..." );
5151
if ( !ba )
5252
{
5353
return;
@@ -57,7 +57,7 @@ void QgsHttpRequestHandler::setHttpResponse( QByteArray *ba, const QString &form
5757
{
5858
return;
5959
}
60-
QgsDebugMsg( "Byte array looks good, setting response..." );
60+
QgsMessageLog::logMessage( "Byte array looks good, setting response..." );
6161
appendBody( *ba );
6262
mInfoFormat = format;
6363
}
@@ -178,7 +178,7 @@ void QgsHttpRequestHandler::sendBody()
178178
// Cannot use addToResponse because it uses printf
179179
size_t result = fwrite(( void* )mBody.data(), mBody.size(), 1, FCGI_stdout );
180180
#ifdef QGISDEBUG
181-
QgsDebugMsg( QString( "Sent %1 blocks of %2 bytes" ).arg( result ).arg( mBody.size() ) );
181+
QgsMessageLog::logMessage( QString( "Sent %1 blocks of %2 bytes" ).arg( result ).arg( mBody.size() ) );
182182
#else
183183
Q_UNUSED( result );
184184
#endif
@@ -194,10 +194,10 @@ void QgsHttpRequestHandler::setPluginFilters( QgsServerFiltersMap pluginFilters
194194

195195
void QgsHttpRequestHandler::sendResponse()
196196
{
197-
QgsDebugMsg( QString( "Sending HTTP response" ) );
197+
QgsMessageLog::logMessage( QString( "Sending HTTP response" ) );
198198
if ( ! responseReady() )
199199
{
200-
QgsDebugMsg( QString( "Trying to send out an invalid response" ) );
200+
QgsMessageLog::logMessage( QString( "Trying to send out an invalid response" ) );
201201
return;
202202
}
203203
#ifdef HAVE_SERVER_PYTHON_PLUGINS
@@ -249,7 +249,7 @@ QString QgsHttpRequestHandler::formatToMimeType( const QString& format ) const
249249
void QgsHttpRequestHandler::setGetMapResponse( const QString& service, QImage* img, int imageQuality = -1 )
250250
{
251251
Q_UNUSED( service );
252-
QgsDebugMsg( "setting getmap response..." );
252+
QgsMessageLog::logMessage( "setting getmap response..." );
253253
if ( img )
254254
{
255255
bool png16Bit = ( mFormatString.compare( "image/png; mode=16bit", Qt::CaseInsensitive ) == 0 );
@@ -258,7 +258,7 @@ void QgsHttpRequestHandler::setGetMapResponse( const QString& service, QImage* i
258258
bool isBase64 = mFormatString.endsWith( ";base64", Qt::CaseInsensitive );
259259
if ( mFormat != "PNG" && mFormat != "JPG" && !png16Bit && !png8Bit && !png1Bit )
260260
{
261-
QgsDebugMsg( "service exception - incorrect image format requested..." );
261+
QgsMessageLog::logMessage( "service exception - incorrect image format requested..." );
262262
setServiceException( QgsMapServiceException( "InvalidFormat", "Output format '" + mFormatString + "' is not supported in the GetMap request" ) );
263263
return;
264264
}
@@ -328,7 +328,7 @@ void QgsHttpRequestHandler::setXmlResponse( const QDomDocument& doc, const QStri
328328
void QgsHttpRequestHandler::setGetFeatureInfoResponse( const QDomDocument& infoDoc, const QString& infoFormat )
329329
{
330330
QByteArray ba;
331-
QgsDebugMsg( "Info format is:" + infoFormat );
331+
QgsMessageLog::logMessage( "Info format is:" + infoFormat );
332332

333333
if ( infoFormat == "text/xml" || infoFormat.startsWith( "application/vnd.ogc.gml" ) )
334334
{
@@ -596,7 +596,7 @@ void QgsHttpRequestHandler::requestStringToParameterMap( const QString& request,
596596

597597
}
598598
parameters.insert( key.toUpper(), value );
599-
QgsDebugMsg( "inserting pair " + key.toUpper() + " // " + value + " into the parameter map" );
599+
QgsMessageLog::logMessage( "inserting pair " + key.toUpper() + " // " + value + " into the parameter map" );
600600
}
601601

602602
//feature info format?
@@ -611,7 +611,7 @@ void QgsHttpRequestHandler::requestStringToParameterMap( const QString& request,
611611
QString formatString = mFormatString;
612612
if ( !formatString.isEmpty() )
613613
{
614-
QgsDebugMsg( QString( "formatString is: %1" ).arg( formatString ) );
614+
QgsMessageLog::logMessage( QString( "formatString is: %1" ).arg( formatString ) );
615615

616616
//remove the image/ in front of the format
617617
if ( formatString.contains( "image/png", Qt::CaseInsensitive ) || formatString.compare( "png", Qt::CaseInsensitive ) == 0 )
@@ -640,6 +640,7 @@ void QgsHttpRequestHandler::requestStringToParameterMap( const QString& request,
640640

641641
QString QgsHttpRequestHandler::readPostBody() const
642642
{
643+
QgsMessageLog::logMessage( "QgsHttpRequestHandler::readPostBody" );
643644
char* lengthString = NULL;
644645
int length = 0;
645646
char* input = NULL;
@@ -652,7 +653,7 @@ QString QgsHttpRequestHandler::readPostBody() const
652653
bool conversionSuccess = false;
653654
lengthQString = QString( lengthString );
654655
length = lengthQString.toInt( &conversionSuccess );
655-
QgsDebugMsg( "length is: " + lengthQString );
656+
QgsMessageLog::logMessage( "length is: " + lengthQString );
656657
if ( conversionSuccess )
657658
{
658659
input = ( char* )malloc( length + 1 );
@@ -668,13 +669,13 @@ QString QgsHttpRequestHandler::readPostBody() const
668669
}
669670
else
670671
{
671-
QgsDebugMsg( "input is NULL " );
672+
QgsMessageLog::logMessage( "input is NULL " );
672673
}
673674
free( input );
674675
}
675676
else
676677
{
677-
QgsDebugMsg( "could not convert CONTENT_LENGTH to int" );
678+
QgsMessageLog::logMessage( "could not convert CONTENT_LENGTH to int" );
678679
}
679680
}
680681
return inputString;

src/server/qgspostrequesthandler.cpp

+13-8
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,12 @@
1616
***************************************************************************/
1717
#include <stdlib.h>
1818
#include "qgspostrequesthandler.h"
19-
#include "qgslogger.h"
19+
#include "qgsmessagelog.h"
2020
#include <QDomDocument>
2121

2222
QgsPostRequestHandler::QgsPostRequestHandler( const bool captureOutput /*= FALSE*/ )
2323
: QgsHttpRequestHandler( captureOutput )
2424
{
25-
2625
}
2726

2827
QgsPostRequestHandler::~QgsPostRequestHandler()
@@ -31,9 +30,10 @@ QgsPostRequestHandler::~QgsPostRequestHandler()
3130

3231
void QgsPostRequestHandler::parseInput()
3332
{
34-
QgsDebugMsg( "QgsPostRequestHandler::parseInput" );
33+
QgsMessageLog::logMessage( "QgsPostRequestHandler::parseInput" );
34+
3535
QString inputString = readPostBody();
36-
QgsDebugMsg( inputString );
36+
QgsMessageLog::logMessage( inputString );
3737

3838
//Map parameter in QUERY_STRING?
3939
const char* qs = getenv( "QUERY_STRING" );
@@ -47,11 +47,16 @@ void QgsPostRequestHandler::parseInput()
4747
mapParameter = getParameters.value( "MAP" );
4848
}
4949

50-
5150
QDomDocument doc;
5251
QString errorMsg;
53-
if ( !doc.setContent( inputString, true, &errorMsg ) )
52+
int line;
53+
int column;
54+
if ( !doc.setContent( inputString, true, &errorMsg, &line, &column ) )
5455
{
56+
char* requestMethod = getenv( "REQUEST_METHOD" );
57+
if ( requestMethod != NULL && strcmp( requestMethod, "POST" ) == 0 ) {
58+
QgsMessageLog::logMessage( QString( "Error at line %1, column %2: %3." ).arg( line ).arg( column ).arg( errorMsg ) );
59+
}
5560
requestStringToParameterMap( inputString, mParameterMap );
5661
}
5762
else
@@ -61,11 +66,11 @@ void QgsPostRequestHandler::parseInput()
6166
if ( qs )
6267
{
6368
queryString = QString( qs );
64-
QgsDebugMsg( "query string is: " + queryString );
69+
QgsMessageLog::logMessage( "query string is: " + queryString );
6570
}
6671
else
6772
{
68-
QgsDebugMsg( "error, no query string found but a QDomDocument" );
73+
QgsMessageLog::logMessage( "error, no query string found but a QDomDocument" );
6974
return; //no query string? something must be wrong...
7075
}
7176

src/server/qgsserver.cpp

+17-17
Original file line numberDiff line numberDiff line change
@@ -94,12 +94,12 @@ void QgsServer::setupNetworkAccessManager()
9494
QNetworkDiskCache *cache = new QNetworkDiskCache( 0 );
9595
QString cacheDirectory = settings.value( "cache/directory", QgsApplication::qgisSettingsDirPath() + "cache" ).toString();
9696
qint64 cacheSize = settings.value( "cache/size", 50 * 1024 * 1024 ).toULongLong();
97-
QgsDebugMsg( QString( "setCacheDirectory: %1" ).arg( cacheDirectory ) );
98-
QgsDebugMsg( QString( "setMaximumCacheSize: %1" ).arg( cacheSize ) );
97+
QgsMessageLog::logMessage( QString( "setCacheDirectory: %1" ).arg( cacheDirectory ), "Server", QgsMessageLog::INFO );
98+
QgsMessageLog::logMessage( QString( "setMaximumCacheSize: %1" ).arg( cacheSize ), "Server", QgsMessageLog::INFO );
9999
cache->setCacheDirectory( cacheDirectory );
100100
cache->setMaximumCacheSize( cacheSize );
101-
QgsDebugMsg( QString( "cacheDirectory: %1" ).arg( cache->cacheDirectory() ) );
102-
QgsDebugMsg( QString( "maximumCacheSize: %1" ).arg( cache->maximumCacheSize() ) );
101+
QgsMessageLog::logMessage( QString( "cacheDirectory: %1" ).arg( cache->cacheDirectory() ), "Server", QgsMessageLog::INFO );
102+
QgsMessageLog::logMessage( QString( "maximumCacheSize: %1" ).arg( cache->maximumCacheSize() ), "Server", QgsMessageLog::INFO );
103103
nam->setCache( cache );
104104
}
105105

@@ -144,7 +144,7 @@ QFileInfo QgsServer::defaultProjectFile()
144144
QFileInfoList projectFiles = currentDir.entryInfoList( nameFilterList, QDir::Files, QDir::Name );
145145
for ( int x = 0; x < projectFiles.size(); x++ )
146146
{
147-
QgsDebugMsg( projectFiles.at( x ).absoluteFilePath() );
147+
QgsMessageLog::logMessage( projectFiles.at( x ).absoluteFilePath(), "Server", QgsMessageLog::INFO );
148148
}
149149
if ( projectFiles.size() < 1 )
150150
{
@@ -271,7 +271,7 @@ QString QgsServer::configPath( const QString& defaultConfigPath, const QMap<QStr
271271
QMap<QString, QString>::const_iterator paramIt = parameters.find( "MAP" );
272272
if ( paramIt == parameters.constEnd() )
273273
{
274-
QgsDebugMsg( QString( "Using default configuration file path: %1" ).arg( defaultConfigPath ) );
274+
QgsMessageLog::logMessage( QString( "Using default configuration file path: %1" ).arg( defaultConfigPath ), "Server", QgsMessageLog::INFO );
275275
}
276276
else
277277
{
@@ -311,14 +311,16 @@ bool QgsServer::init( int & argc, char ** argv )
311311
return false;
312312
}
313313

314+
QgsServerLogger::instance();
315+
314316
#ifndef _MSC_VER
315317
qInstallMsgHandler( dummyMessageHandler );
316318
#endif
317319

318320
QString optionsPath = getenv( "QGIS_OPTIONS_PATH" );
319321
if ( !optionsPath.isEmpty() )
320322
{
321-
QgsDebugMsg( "Options PATH: " + optionsPath );
323+
QgsMessageLog::logMessage( "Options PATH: " + optionsPath, "Server", QgsMessageLog::INFO );
322324
QSettings::setDefaultFormat( QSettings::IniFormat );
323325
QSettings::setPath( QSettings::IniFormat, QSettings::UserScope, optionsPath );
324326
}
@@ -337,7 +339,7 @@ bool QgsServer::init( int & argc, char ** argv )
337339
#endif
338340

339341
#if defined(SERVER_SKIP_ECW)
340-
QgsDebugMsg( "Skipping GDAL ECW drivers in server." );
342+
QgsMessageLog::logMessage( "Skipping GDAL ECW drivers in server.", "Server", QgsMessageLog::INFO );
341343
QgsApplication::skipGdalDriver( "ECW" );
342344
QgsApplication::skipGdalDriver( "JP2ECW" );
343345
#endif
@@ -347,12 +349,12 @@ bool QgsServer::init( int & argc, char ** argv )
347349

348350
// Instantiate the plugin directory so that providers are loaded
349351
QgsProviderRegistry::instance( QgsApplication::pluginPath() );
350-
QgsDebugMsg( "Prefix PATH: " + QgsApplication::prefixPath() );
351-
QgsDebugMsg( "Plugin PATH: " + QgsApplication::pluginPath() );
352-
QgsDebugMsg( "PkgData PATH: " + QgsApplication::pkgDataPath() );
353-
QgsDebugMsg( "User DB PATH: " + QgsApplication::qgisUserDbFilePath() );
354-
QgsDebugMsg( "Auth DB PATH: " + QgsApplication::qgisAuthDbFilePath() );
355-
QgsDebugMsg( "SVG PATHS: " + QgsApplication::svgPaths().join( ":" ) );
352+
QgsMessageLog::logMessage( "Prefix PATH: " + QgsApplication::prefixPath(), "Server", QgsMessageLog::INFO );
353+
QgsMessageLog::logMessage( "Plugin PATH: " + QgsApplication::pluginPath(), "Server", QgsMessageLog::INFO );
354+
QgsMessageLog::logMessage( "PkgData PATH: " + QgsApplication::pkgDataPath(), "Server", QgsMessageLog::INFO );
355+
QgsMessageLog::logMessage( "User DB PATH: " + QgsApplication::qgisUserDbFilePath(), "Server", QgsMessageLog::INFO );
356+
QgsMessageLog::logMessage( "Auth DB PATH: " + QgsApplication::qgisAuthDbFilePath(), "Server", QgsMessageLog::INFO );
357+
QgsMessageLog::logMessage( "SVG PATHS: " + QgsApplication::svgPaths().join( ":" ), "Server", QgsMessageLog::INFO );
356358

357359
QgsApplication::createDB(); //init qgis.db (e.g. necessary for user crs)
358360

@@ -367,7 +369,7 @@ bool QgsServer::init( int & argc, char ** argv )
367369
if ( projectFileInfo.exists() )
368370
{
369371
defaultConfigFilePath = projectFileInfo.absoluteFilePath();
370-
QgsDebugMsg( "Using default project file: " + defaultConfigFilePath );
372+
QgsMessageLog::logMessage( "Using default project file: " + defaultConfigFilePath, "Server", QgsMessageLog::INFO );
371373
}
372374
else
373375
{
@@ -407,8 +409,6 @@ bool QgsServer::init( int & argc, char ** argv )
407409
}
408410
#endif
409411

410-
QgsServerLogger::instance();
411-
412412
QgsEditorWidgetRegistry::initEditors();
413413
mInitialised = true;
414414
QgsMessageLog::logMessage( "Server intialised", "Server", QgsMessageLog::INFO );

src/server/qgsserverplugins.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ bool QgsServerPlugins::initPlugins( QgsServerInterface *interface )
4747
pythonlibName.prepend( "lib" );
4848
#endif
4949
QString version = QString( "%1.%2.%3" ).arg( QGis::QGIS_VERSION_INT / 10000 ).arg( QGis::QGIS_VERSION_INT / 100 % 100 ).arg( QGis::QGIS_VERSION_INT % 100 );
50-
QgsDebugMsg( QString( "load library %1 (%2)" ).arg( pythonlibName ).arg( version ) );
50+
QgsMessageLog::logMessage( QString( "load library %1 (%2)" ).arg( pythonlibName ).arg( version ), __FILE__, QgsMessageLog::INFO );
5151
QLibrary pythonlib( pythonlibName, version );
5252
// It's necessary to set these two load hints, otherwise Python library won't work correctly
5353
// see http://lists.kde.org/?l=pykde&m=117190116820758&w=2
@@ -57,12 +57,12 @@ bool QgsServerPlugins::initPlugins( QgsServerInterface *interface )
5757
pythonlib.setFileName( pythonlibName );
5858
if ( !pythonlib.load() )
5959
{
60-
QgsDebugMsg( QString( "Couldn't load Python support library: %1" ).arg( pythonlib.errorString() ) );
60+
QgsMessageLog::logMessage( QString( "Couldn't load Python support library: %1" ).arg( pythonlib.errorString() ) );
6161
return false;
6262
}
6363
}
6464

65-
QgsDebugMsg( "Python support library loaded successfully." );
65+
QgsMessageLog::logMessage( "Python support library loaded successfully.", __FILE__, QgsMessageLog::INFO );
6666
typedef QgsPythonUtils*( *inst )();
6767
inst pythonlib_inst = ( inst ) cast_to_fptr( pythonlib.resolve( "instance" ) );
6868
if ( !pythonlib_inst )

0 commit comments

Comments
 (0)