Skip to content

Commit

Permalink
Make log messages visible in the QGIS server log file
Browse files Browse the repository at this point in the history
  • Loading branch information
sbrunner committed Nov 18, 2015
1 parent e0bedc2 commit b1743dc
Show file tree
Hide file tree
Showing 6 changed files with 97 additions and 89 deletions.
29 changes: 15 additions & 14 deletions src/server/qgshttprequesthandler.cpp
Expand Up @@ -20,7 +20,7 @@
#include "qgshttprequesthandler.h"
#include "qgsftptransaction.h"
#include "qgshttptransaction.h"
#include "qgslogger.h"
#include "qgsmessagelog.h"
#include "qgsmapserviceexception.h"
#include <QBuffer>
#include <QByteArray>
Expand All @@ -47,7 +47,7 @@ QgsHttpRequestHandler::~QgsHttpRequestHandler()

void QgsHttpRequestHandler::setHttpResponse( QByteArray *ba, const QString &format )
{
QgsDebugMsg( "Checking byte array is ok to set..." );
QgsMessageLog::logMessage( "Checking byte array is ok to set..." );
if ( !ba )
{
return;
Expand All @@ -57,7 +57,7 @@ void QgsHttpRequestHandler::setHttpResponse( QByteArray *ba, const QString &form
{
return;
}
QgsDebugMsg( "Byte array looks good, setting response..." );
QgsMessageLog::logMessage( "Byte array looks good, setting response..." );
appendBody( *ba );
mInfoFormat = format;
}
Expand Down Expand Up @@ -178,7 +178,7 @@ void QgsHttpRequestHandler::sendBody()
// Cannot use addToResponse because it uses printf
size_t result = fwrite(( void* )mBody.data(), mBody.size(), 1, FCGI_stdout );
#ifdef QGISDEBUG
QgsDebugMsg( QString( "Sent %1 blocks of %2 bytes" ).arg( result ).arg( mBody.size() ) );
QgsMessageLog::logMessage( QString( "Sent %1 blocks of %2 bytes" ).arg( result ).arg( mBody.size() ) );
#else
Q_UNUSED( result );
#endif
Expand All @@ -194,10 +194,10 @@ void QgsHttpRequestHandler::setPluginFilters( QgsServerFiltersMap pluginFilters

void QgsHttpRequestHandler::sendResponse()
{
QgsDebugMsg( QString( "Sending HTTP response" ) );
QgsMessageLog::logMessage( QString( "Sending HTTP response" ) );
if ( ! responseReady() )
{
QgsDebugMsg( QString( "Trying to send out an invalid response" ) );
QgsMessageLog::logMessage( QString( "Trying to send out an invalid response" ) );
return;
}
#ifdef HAVE_SERVER_PYTHON_PLUGINS
Expand Down Expand Up @@ -249,7 +249,7 @@ QString QgsHttpRequestHandler::formatToMimeType( const QString& format ) const
void QgsHttpRequestHandler::setGetMapResponse( const QString& service, QImage* img, int imageQuality = -1 )
{
Q_UNUSED( service );
QgsDebugMsg( "setting getmap response..." );
QgsMessageLog::logMessage( "setting getmap response..." );
if ( img )
{
bool png16Bit = ( mFormatString.compare( "image/png; mode=16bit", Qt::CaseInsensitive ) == 0 );
Expand All @@ -258,7 +258,7 @@ void QgsHttpRequestHandler::setGetMapResponse( const QString& service, QImage* i
bool isBase64 = mFormatString.endsWith( ";base64", Qt::CaseInsensitive );
if ( mFormat != "PNG" && mFormat != "JPG" && !png16Bit && !png8Bit && !png1Bit )
{
QgsDebugMsg( "service exception - incorrect image format requested..." );
QgsMessageLog::logMessage( "service exception - incorrect image format requested..." );
setServiceException( QgsMapServiceException( "InvalidFormat", "Output format '" + mFormatString + "' is not supported in the GetMap request" ) );
return;
}
Expand Down Expand Up @@ -328,7 +328,7 @@ void QgsHttpRequestHandler::setXmlResponse( const QDomDocument& doc, const QStri
void QgsHttpRequestHandler::setGetFeatureInfoResponse( const QDomDocument& infoDoc, const QString& infoFormat )
{
QByteArray ba;
QgsDebugMsg( "Info format is:" + infoFormat );
QgsMessageLog::logMessage( "Info format is:" + infoFormat );

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

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

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

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

QString QgsHttpRequestHandler::readPostBody() const
{
QgsMessageLog::logMessage( "QgsHttpRequestHandler::readPostBody" );
char* lengthString = NULL;
int length = 0;
char* input = NULL;
Expand All @@ -652,7 +653,7 @@ QString QgsHttpRequestHandler::readPostBody() const
bool conversionSuccess = false;
lengthQString = QString( lengthString );
length = lengthQString.toInt( &conversionSuccess );
QgsDebugMsg( "length is: " + lengthQString );
QgsMessageLog::logMessage( "length is: " + lengthQString );
if ( conversionSuccess )
{
input = ( char* )malloc( length + 1 );
Expand All @@ -668,13 +669,13 @@ QString QgsHttpRequestHandler::readPostBody() const
}
else
{
QgsDebugMsg( "input is NULL " );
QgsMessageLog::logMessage( "input is NULL " );
}
free( input );
}
else
{
QgsDebugMsg( "could not convert CONTENT_LENGTH to int" );
QgsMessageLog::logMessage( "could not convert CONTENT_LENGTH to int" );
}
}
return inputString;
Expand Down
21 changes: 13 additions & 8 deletions src/server/qgspostrequesthandler.cpp
Expand Up @@ -16,13 +16,12 @@
***************************************************************************/
#include <stdlib.h>
#include "qgspostrequesthandler.h"
#include "qgslogger.h"
#include "qgsmessagelog.h"
#include <QDomDocument>

QgsPostRequestHandler::QgsPostRequestHandler( const bool captureOutput /*= FALSE*/ )
: QgsHttpRequestHandler( captureOutput )
{

}

QgsPostRequestHandler::~QgsPostRequestHandler()
Expand All @@ -31,9 +30,10 @@ QgsPostRequestHandler::~QgsPostRequestHandler()

void QgsPostRequestHandler::parseInput()
{
QgsDebugMsg( "QgsPostRequestHandler::parseInput" );
QgsMessageLog::logMessage( "QgsPostRequestHandler::parseInput" );

QString inputString = readPostBody();
QgsDebugMsg( inputString );
QgsMessageLog::logMessage( inputString );

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


QDomDocument doc;
QString errorMsg;
if ( !doc.setContent( inputString, true, &errorMsg ) )
int line;
int column;
if ( !doc.setContent( inputString, true, &errorMsg, &line, &column ) )
{
char* requestMethod = getenv( "REQUEST_METHOD" );
if ( requestMethod != NULL && strcmp( requestMethod, "POST" ) == 0 ) {
QgsMessageLog::logMessage( QString( "Error at line %1, column %2: %3." ).arg( line ).arg( column ).arg( errorMsg ) );
}
requestStringToParameterMap( inputString, mParameterMap );
}
else
Expand All @@ -61,11 +66,11 @@ void QgsPostRequestHandler::parseInput()
if ( qs )
{
queryString = QString( qs );
QgsDebugMsg( "query string is: " + queryString );
QgsMessageLog::logMessage( "query string is: " + queryString );
}
else
{
QgsDebugMsg( "error, no query string found but a QDomDocument" );
QgsMessageLog::logMessage( "error, no query string found but a QDomDocument" );
return; //no query string? something must be wrong...
}

Expand Down
34 changes: 17 additions & 17 deletions src/server/qgsserver.cpp
Expand Up @@ -94,12 +94,12 @@ void QgsServer::setupNetworkAccessManager()
QNetworkDiskCache *cache = new QNetworkDiskCache( 0 );
QString cacheDirectory = settings.value( "cache/directory", QgsApplication::qgisSettingsDirPath() + "cache" ).toString();
qint64 cacheSize = settings.value( "cache/size", 50 * 1024 * 1024 ).toULongLong();
QgsDebugMsg( QString( "setCacheDirectory: %1" ).arg( cacheDirectory ) );
QgsDebugMsg( QString( "setMaximumCacheSize: %1" ).arg( cacheSize ) );
QgsMessageLog::logMessage( QString( "setCacheDirectory: %1" ).arg( cacheDirectory ), "Server", QgsMessageLog::INFO );
QgsMessageLog::logMessage( QString( "setMaximumCacheSize: %1" ).arg( cacheSize ), "Server", QgsMessageLog::INFO );
cache->setCacheDirectory( cacheDirectory );
cache->setMaximumCacheSize( cacheSize );
QgsDebugMsg( QString( "cacheDirectory: %1" ).arg( cache->cacheDirectory() ) );
QgsDebugMsg( QString( "maximumCacheSize: %1" ).arg( cache->maximumCacheSize() ) );
QgsMessageLog::logMessage( QString( "cacheDirectory: %1" ).arg( cache->cacheDirectory() ), "Server", QgsMessageLog::INFO );
QgsMessageLog::logMessage( QString( "maximumCacheSize: %1" ).arg( cache->maximumCacheSize() ), "Server", QgsMessageLog::INFO );
nam->setCache( cache );
}

Expand Down Expand Up @@ -144,7 +144,7 @@ QFileInfo QgsServer::defaultProjectFile()
QFileInfoList projectFiles = currentDir.entryInfoList( nameFilterList, QDir::Files, QDir::Name );
for ( int x = 0; x < projectFiles.size(); x++ )
{
QgsDebugMsg( projectFiles.at( x ).absoluteFilePath() );
QgsMessageLog::logMessage( projectFiles.at( x ).absoluteFilePath(), "Server", QgsMessageLog::INFO );
}
if ( projectFiles.size() < 1 )
{
Expand Down Expand Up @@ -271,7 +271,7 @@ QString QgsServer::configPath( const QString& defaultConfigPath, const QMap<QStr
QMap<QString, QString>::const_iterator paramIt = parameters.find( "MAP" );
if ( paramIt == parameters.constEnd() )
{
QgsDebugMsg( QString( "Using default configuration file path: %1" ).arg( defaultConfigPath ) );
QgsMessageLog::logMessage( QString( "Using default configuration file path: %1" ).arg( defaultConfigPath ), "Server", QgsMessageLog::INFO );
}
else
{
Expand Down Expand Up @@ -311,14 +311,16 @@ bool QgsServer::init( int & argc, char ** argv )
return false;
}

QgsServerLogger::instance();

#ifndef _MSC_VER
qInstallMsgHandler( dummyMessageHandler );
#endif

QString optionsPath = getenv( "QGIS_OPTIONS_PATH" );
if ( !optionsPath.isEmpty() )
{
QgsDebugMsg( "Options PATH: " + optionsPath );
QgsMessageLog::logMessage( "Options PATH: " + optionsPath, "Server", QgsMessageLog::INFO );
QSettings::setDefaultFormat( QSettings::IniFormat );
QSettings::setPath( QSettings::IniFormat, QSettings::UserScope, optionsPath );
}
Expand All @@ -337,7 +339,7 @@ bool QgsServer::init( int & argc, char ** argv )
#endif

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

// Instantiate the plugin directory so that providers are loaded
QgsProviderRegistry::instance( QgsApplication::pluginPath() );
QgsDebugMsg( "Prefix PATH: " + QgsApplication::prefixPath() );
QgsDebugMsg( "Plugin PATH: " + QgsApplication::pluginPath() );
QgsDebugMsg( "PkgData PATH: " + QgsApplication::pkgDataPath() );
QgsDebugMsg( "User DB PATH: " + QgsApplication::qgisUserDbFilePath() );
QgsDebugMsg( "Auth DB PATH: " + QgsApplication::qgisAuthDbFilePath() );
QgsDebugMsg( "SVG PATHS: " + QgsApplication::svgPaths().join( ":" ) );
QgsMessageLog::logMessage( "Prefix PATH: " + QgsApplication::prefixPath(), "Server", QgsMessageLog::INFO );
QgsMessageLog::logMessage( "Plugin PATH: " + QgsApplication::pluginPath(), "Server", QgsMessageLog::INFO );
QgsMessageLog::logMessage( "PkgData PATH: " + QgsApplication::pkgDataPath(), "Server", QgsMessageLog::INFO );
QgsMessageLog::logMessage( "User DB PATH: " + QgsApplication::qgisUserDbFilePath(), "Server", QgsMessageLog::INFO );
QgsMessageLog::logMessage( "Auth DB PATH: " + QgsApplication::qgisAuthDbFilePath(), "Server", QgsMessageLog::INFO );
QgsMessageLog::logMessage( "SVG PATHS: " + QgsApplication::svgPaths().join( ":" ), "Server", QgsMessageLog::INFO );

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

Expand All @@ -367,7 +369,7 @@ bool QgsServer::init( int & argc, char ** argv )
if ( projectFileInfo.exists() )
{
defaultConfigFilePath = projectFileInfo.absoluteFilePath();
QgsDebugMsg( "Using default project file: " + defaultConfigFilePath );
QgsMessageLog::logMessage( "Using default project file: " + defaultConfigFilePath, "Server", QgsMessageLog::INFO );
}
else
{
Expand Down Expand Up @@ -407,8 +409,6 @@ bool QgsServer::init( int & argc, char ** argv )
}
#endif

QgsServerLogger::instance();

QgsEditorWidgetRegistry::initEditors();
mInitialised = true;
QgsMessageLog::logMessage( "Server intialised", "Server", QgsMessageLog::INFO );
Expand Down
6 changes: 3 additions & 3 deletions src/server/qgsserverplugins.cpp
Expand Up @@ -47,7 +47,7 @@ bool QgsServerPlugins::initPlugins( QgsServerInterface *interface )
pythonlibName.prepend( "lib" );
#endif
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 );
QgsDebugMsg( QString( "load library %1 (%2)" ).arg( pythonlibName ).arg( version ) );
QgsMessageLog::logMessage( QString( "load library %1 (%2)" ).arg( pythonlibName ).arg( version ), __FILE__, QgsMessageLog::INFO );
QLibrary pythonlib( pythonlibName, version );
// It's necessary to set these two load hints, otherwise Python library won't work correctly
// see http://lists.kde.org/?l=pykde&m=117190116820758&w=2
Expand All @@ -57,12 +57,12 @@ bool QgsServerPlugins::initPlugins( QgsServerInterface *interface )
pythonlib.setFileName( pythonlibName );
if ( !pythonlib.load() )
{
QgsDebugMsg( QString( "Couldn't load Python support library: %1" ).arg( pythonlib.errorString() ) );
QgsMessageLog::logMessage( QString( "Couldn't load Python support library: %1" ).arg( pythonlib.errorString() ) );
return false;
}
}

QgsDebugMsg( "Python support library loaded successfully." );
QgsMessageLog::logMessage( "Python support library loaded successfully.", __FILE__, QgsMessageLog::INFO );
typedef QgsPythonUtils*( *inst )();
inst pythonlib_inst = ( inst ) cast_to_fptr( pythonlib.resolve( "instance" ) );
if ( !pythonlib_inst )
Expand Down

0 comments on commit b1743dc

Please sign in to comment.