3232#include " qgsmapserviceexception.h"
3333#include " qgspallabeling.h"
3434#include " qgsnetworkaccessmanager.h"
35+ #include " qgsserverlogger.h"
3536
3637#include < QDomDocument>
3738#include < QNetworkDiskCache>
4748
4849void dummyMessageHandler ( QtMsgType type, const char *msg )
4950{
50- #ifdef QGSMSDEBUG
51+ #if 0 //def QGSMSDEBUG
5152 QString output;
5253
5354 switch ( type )
@@ -79,53 +80,61 @@ void dummyMessageHandler( QtMsgType type, const char *msg )
7980
8081void printRequestInfos ()
8182{
82- #ifdef QGSMSDEBUG
83- // print out some infos about the request
84- QgsDebugMsg ( " ************************new request**********************" );
85- QgsDebugMsg ( QDateTime::currentDateTime ().toString ( " yyyy-MM-dd hh:mm:ss" ) );
86-
83+ QgsMessageLog::logMessage ( " ********************new request***************" , " Server" , QgsMessageLog::INFO );
8784 if ( getenv ( " REMOTE_ADDR" ) != NULL )
8885 {
89- QgsDebugMsg ( " remote ip: " + QString ( getenv ( " REMOTE_ADDR" ) ) );
86+ QgsMessageLog::logMessage ( " remote ip: " + QString ( getenv ( " REMOTE_ADDR" ) ), " Server " , QgsMessageLog:: INFO );
9087 }
9188 if ( getenv ( " REMOTE_HOST" ) != NULL )
9289 {
93- QgsDebugMsg ( " remote host : " + QString ( getenv ( " REMOTE_HOST " ) ) );
90+ QgsMessageLog::logMessage ( " remote ip : " + QString ( getenv ( " REMOTE_ADDR " ) ), " Server " , QgsMessageLog:: INFO );
9491 }
9592 if ( getenv ( " REMOTE_USER" ) != NULL )
9693 {
97- QgsDebugMsg ( " remote user: " + QString ( getenv ( " REMOTE_USER" ) ) );
94+ QgsMessageLog::logMessage ( " remote user: " + QString ( getenv ( " REMOTE_USER" ) ), " Server " , QgsMessageLog:: INFO );
9895 }
9996 if ( getenv ( " REMOTE_IDENT" ) != NULL )
10097 {
101- QgsDebugMsg ( " REMOTE_IDENT: " + QString ( getenv ( " REMOTE_IDENT" ) ) );
98+ QgsMessageLog::logMessage ( " REMOTE_IDENT: " + QString ( getenv ( " REMOTE_IDENT" ) ), " Server " , QgsMessageLog:: INFO );
10299 }
103100 if ( getenv ( " CONTENT_TYPE" ) != NULL )
104101 {
105- QgsDebugMsg ( " CONTENT_TYPE: " + QString ( getenv ( " CONTENT_TYPE" ) ) );
102+ QgsMessageLog::logMessage ( " CONTENT_TYPE: " + QString ( getenv ( " CONTENT_TYPE" ) ), " Server " , QgsMessageLog:: INFO );
106103 }
107104 if ( getenv ( " AUTH_TYPE" ) != NULL )
108105 {
109- QgsDebugMsg ( " AUTH_TYPE: " + QString ( getenv ( " AUTH_TYPE" ) ) );
106+ QgsMessageLog::logMessage ( " AUTH_TYPE: " + QString ( getenv ( " AUTH_TYPE" ) ), " Server " , QgsMessageLog:: INFO );
110107 }
111108 if ( getenv ( " HTTP_USER_AGENT" ) != NULL )
112109 {
113- QgsDebugMsg ( " HTTP_USER_AGENT: " + QString ( getenv ( " HTTP_USER_AGENT" ) ) );
110+ QgsMessageLog::logMessage ( " HTTP_USER_AGENT: " + QString ( getenv ( " HTTP_USER_AGENT" ) ), " Server " , QgsMessageLog:: INFO );
114111 }
115112 if ( getenv ( " HTTP_PROXY" ) != NULL )
116113 {
117- QgsDebugMsg ( " HTTP_PROXY: " + QString ( getenv ( " HTTP_PROXY" ) ) );
114+ QgsMessageLog::logMessage ( " HTTP_PROXY: " + QString ( getenv ( " HTTP_PROXY" ) ), " Server " , QgsMessageLog:: INFO );
118115 }
119116 if ( getenv ( " HTTPS_PROXY" ) != NULL )
120117 {
121- QgsDebugMsg ( " HTTPS_PROXY: " + QString ( getenv ( " HTTPS_PROXY" ) ) );
118+ QgsMessageLog::logMessage ( " HTTPS_PROXY: " + QString ( getenv ( " HTTPS_PROXY" ) ), " Server " , QgsMessageLog:: INFO );
122119 }
123120 if ( getenv ( " NO_PROXY" ) != NULL )
124121 {
125- QgsDebugMsg ( " NO_PROXY: " + QString ( getenv ( " NO_PROXY" ) ) );
122+ QgsMessageLog::logMessage ( " NO_PROXY: " + QString ( getenv ( " NO_PROXY" ) ), " Server" , QgsMessageLog::INFO );
123+ }
124+ }
125+
126+ void printRequestParameters ( const QMap< QString, QString>& parameterMap, int logLevel )
127+ {
128+ if ( logLevel > 0 )
129+ {
130+ return ;
126131 }
127132
128- #endif // QGSMSDEBUG
133+ QMap< QString, QString>::const_iterator pIt = parameterMap.constBegin ();
134+ for ( ; pIt != parameterMap.constEnd (); ++pIt )
135+ {
136+ QgsMessageLog::logMessage ( pIt.key () + " :" + pIt.value (), " Server" , QgsMessageLog::INFO );
137+ }
129138}
130139
131140QFileInfo defaultProjectFile ()
@@ -287,21 +296,17 @@ int main( int argc, char * argv[] )
287296 QgsFontUtils::loadStandardTestFonts ( QStringList () << " Roman" << " Bold" );
288297#endif
289298
290- QString logFile = QgsLogger::logFile ();
299+ int logLevel = QgsServerLogger::instance ()->logLevel ();
300+ QTime time; // used for measuring request time if loglevel < 1
291301
292302 while ( fcgi_accept () >= 0 )
293303 {
294- if ( !logFile. isEmpty () )
304+ if ( logLevel < 1 )
295305 {
296- #ifdef Q_WS_WIN
297- putenv ( QString ( " QGIS_LOG_FILE=%1" ).arg ( logFile ).toLocal8Bit ().constData () );
298- #else
299- setenv ( " QGIS_LOG_FILE" , logFile.toLocal8Bit ().constData (), 1 );
300- #endif
306+ time.start ();
307+ printRequestInfos ();
301308 }
302309
303- printRequestInfos (); // print request infos if in debug mode
304-
305310 // Request handler
306311 QgsRequestHandler* theRequestHandler = createRequestHandler ();
307312 QMap<QString, QString> parameterMap;
@@ -311,11 +316,12 @@ int main( int argc, char * argv[] )
311316 }
312317 catch ( QgsMapServiceException& e )
313318 {
314- QgsDebugMsg ( " An exception was thrown during input parsing " );
319+ QgsMessageLog::logMessage ( " Parse input exception: " + e. message (), " Server " , QgsMessageLog:: CRITICAL );
315320 theRequestHandler->sendServiceException ( e );
316321 continue ;
317322 }
318323
324+ printRequestParameters ( parameterMap, logLevel );
319325 QMap<QString, QString>::const_iterator paramIt;
320326
321327 // Config file path
@@ -326,6 +332,7 @@ int main( int argc, char * argv[] )
326332 paramIt = parameterMap.find ( " SERVICE" );
327333 if ( paramIt == parameterMap.constEnd () )
328334 {
335+ QgsMessageLog::logMessage ( " Exception: SERVICE parameter is missing" , " Server" , QgsMessageLog::CRITICAL );
329336 theRequestHandler->sendServiceException ( QgsMapServiceException ( " ServiceNotSpecified" , " Service not specified. The SERVICE parameter is mandatory" ) );
330337 delete theRequestHandler;
331338 continue ;
@@ -340,7 +347,8 @@ int main( int argc, char * argv[] )
340347 QgsWCSProjectParser* p = QgsConfigCache::instance ()->wcsConfiguration ( configFilePath );
341348 if ( !p )
342349 {
343- // error handling
350+ theRequestHandler->sendServiceException ( QgsMapServiceException ( " Project file error" , " Error reading the project file" ) );
351+ continue ;
344352 }
345353 QgsWCSServer wcsServer ( configFilePath, parameterMap, p, theRequestHandler );
346354 wcsServer.executeRequest ();
@@ -350,7 +358,8 @@ int main( int argc, char * argv[] )
350358 QgsWFSProjectParser* p = QgsConfigCache::instance ()->wfsConfiguration ( configFilePath );
351359 if ( !p )
352360 {
353- // error handling
361+ theRequestHandler->sendServiceException ( QgsMapServiceException ( " Project file error" , " Error reading the project file" ) );
362+ continue ;
354363 }
355364 QgsWFSServer wfsServer ( configFilePath, parameterMap, p, theRequestHandler );
356365 wfsServer.executeRequest ();
@@ -360,12 +369,18 @@ int main( int argc, char * argv[] )
360369 QgsWMSConfigParser* p = QgsConfigCache::instance ()->wmsConfiguration ( configFilePath, parameterMap );
361370 if ( !p )
362371 {
363- // error handling
372+ theRequestHandler->sendServiceException ( QgsMapServiceException ( " WMS configuration error" , " There was an error reading gthe project file or the SLD configuration" ) );
373+ continue ;
364374 }
365375 // adminConfigParser->loadLabelSettings( theMapRenderer->labelingEngine() );
366376 QgsWMSServer wmsServer ( configFilePath, parameterMap, p, theRequestHandler, theMapRenderer, &capabilitiesCache );
367377 wmsServer.executeRequest ();
368378 }
379+
380+ if ( logLevel < 1 )
381+ {
382+ QgsMessageLog::logMessage ( " Request finished in " + QString::number ( time.elapsed () ) + " ms" , " Server" , QgsMessageLog::INFO );
383+ }
369384 }
370385
371386 delete theMapRenderer;
0 commit comments