33
33
#include " qgspallabeling.h"
34
34
#include " qgsnetworkaccessmanager.h"
35
35
#include " qgsmaplayerregistry.h"
36
+ #include " qgsserverlogger.h"
36
37
37
38
#include < QDomDocument>
38
39
#include < QNetworkDiskCache>
49
50
50
51
void dummyMessageHandler ( QtMsgType type, const char *msg )
51
52
{
52
- #ifdef QGSMSDEBUG
53
+ #if 0 //def QGSMSDEBUG
53
54
QString output;
54
55
55
56
switch ( type )
@@ -81,53 +82,61 @@ void dummyMessageHandler( QtMsgType type, const char *msg )
81
82
82
83
void printRequestInfos ()
83
84
{
84
- #ifdef QGSMSDEBUG
85
- // print out some infos about the request
86
- QgsDebugMsg ( " ************************new request**********************" );
87
- QgsDebugMsg ( QDateTime::currentDateTime ().toString ( " yyyy-MM-dd hh:mm:ss" ) );
88
-
85
+ QgsMessageLog::logMessage ( " ********************new request***************" , " Server" , QgsMessageLog::INFO );
89
86
if ( getenv ( " REMOTE_ADDR" ) != NULL )
90
87
{
91
- QgsDebugMsg ( " remote ip: " + QString ( getenv ( " REMOTE_ADDR" ) ) );
88
+ QgsMessageLog::logMessage ( " remote ip: " + QString ( getenv ( " REMOTE_ADDR" ) ), " Server " , QgsMessageLog::INFO );
92
89
}
93
90
if ( getenv ( " REMOTE_HOST" ) != NULL )
94
91
{
95
- QgsDebugMsg ( " remote host : " + QString ( getenv ( " REMOTE_HOST " ) ) );
92
+ QgsMessageLog::logMessage ( " remote ip : " + QString ( getenv ( " REMOTE_ADDR " ) ), " Server " , QgsMessageLog::INFO );
96
93
}
97
94
if ( getenv ( " REMOTE_USER" ) != NULL )
98
95
{
99
- QgsDebugMsg ( " remote user: " + QString ( getenv ( " REMOTE_USER" ) ) );
96
+ QgsMessageLog::logMessage ( " remote user: " + QString ( getenv ( " REMOTE_USER" ) ), " Server " , QgsMessageLog::INFO );
100
97
}
101
98
if ( getenv ( " REMOTE_IDENT" ) != NULL )
102
99
{
103
- QgsDebugMsg ( " REMOTE_IDENT: " + QString ( getenv ( " REMOTE_IDENT" ) ) );
100
+ QgsMessageLog::logMessage ( " REMOTE_IDENT: " + QString ( getenv ( " REMOTE_IDENT" ) ), " Server " , QgsMessageLog::INFO );
104
101
}
105
102
if ( getenv ( " CONTENT_TYPE" ) != NULL )
106
103
{
107
- QgsDebugMsg ( " CONTENT_TYPE: " + QString ( getenv ( " CONTENT_TYPE" ) ) );
104
+ QgsMessageLog::logMessage ( " CONTENT_TYPE: " + QString ( getenv ( " CONTENT_TYPE" ) ), " Server " , QgsMessageLog::INFO );
108
105
}
109
106
if ( getenv ( " AUTH_TYPE" ) != NULL )
110
107
{
111
- QgsDebugMsg ( " AUTH_TYPE: " + QString ( getenv ( " AUTH_TYPE" ) ) );
108
+ QgsMessageLog::logMessage ( " AUTH_TYPE: " + QString ( getenv ( " AUTH_TYPE" ) ), " Server " , QgsMessageLog::INFO );
112
109
}
113
110
if ( getenv ( " HTTP_USER_AGENT" ) != NULL )
114
111
{
115
- QgsDebugMsg ( " HTTP_USER_AGENT: " + QString ( getenv ( " HTTP_USER_AGENT" ) ) );
112
+ QgsMessageLog::logMessage ( " HTTP_USER_AGENT: " + QString ( getenv ( " HTTP_USER_AGENT" ) ), " Server " , QgsMessageLog::INFO );
116
113
}
117
114
if ( getenv ( " HTTP_PROXY" ) != NULL )
118
115
{
119
- QgsDebugMsg ( " HTTP_PROXY: " + QString ( getenv ( " HTTP_PROXY" ) ) );
116
+ QgsMessageLog::logMessage ( " HTTP_PROXY: " + QString ( getenv ( " HTTP_PROXY" ) ), " Server " , QgsMessageLog::INFO );
120
117
}
121
118
if ( getenv ( " HTTPS_PROXY" ) != NULL )
122
119
{
123
- QgsDebugMsg ( " HTTPS_PROXY: " + QString ( getenv ( " HTTPS_PROXY" ) ) );
120
+ QgsMessageLog::logMessage ( " HTTPS_PROXY: " + QString ( getenv ( " HTTPS_PROXY" ) ), " Server " , QgsMessageLog::INFO );
124
121
}
125
122
if ( getenv ( " NO_PROXY" ) != NULL )
126
123
{
127
- QgsDebugMsg ( " NO_PROXY: " + QString ( getenv ( " NO_PROXY" ) ) );
124
+ QgsMessageLog::logMessage ( " NO_PROXY: " + QString ( getenv ( " NO_PROXY" ) ), " Server " , QgsMessageLog::INFO );
128
125
}
126
+ }
129
127
130
- #endif // QGSMSDEBUG
128
+ void printRequestParameters ( const QMap< QString, QString>& parameterMap, int logLevel )
129
+ {
130
+ if ( logLevel > 0 )
131
+ {
132
+ return ;
133
+ }
134
+
135
+ QMap< QString, QString>::const_iterator pIt = parameterMap.constBegin ();
136
+ for ( ; pIt != parameterMap.constEnd (); ++pIt )
137
+ {
138
+ QgsMessageLog::logMessage ( pIt.key () + " :" + pIt.value (), " Server" , QgsMessageLog::INFO );
139
+ }
131
140
}
132
141
133
142
QFileInfo defaultProjectFile ()
@@ -289,25 +298,20 @@ int main( int argc, char * argv[] )
289
298
QgsFontUtils::loadStandardTestFonts ( QStringList () << " Roman" << " Bold" );
290
299
#endif
291
300
292
- QString logFile = QgsLogger::logFile ();
301
+ int logLevel = QgsServerLogger::instance ()->logLevel ();
302
+ QTime time; // used for measuring request time if loglevel < 1
293
303
294
304
while ( fcgi_accept () >= 0 )
295
305
{
296
306
QgsMapLayerRegistry::instance ()->removeAllMapLayers ();
297
307
qgsapp.processEvents ();
298
308
299
-
300
- if ( !logFile.isEmpty () )
309
+ if ( logLevel < 1 )
301
310
{
302
- #ifdef Q_WS_WIN
303
- putenv ( QString ( " QGIS_LOG_FILE=%1" ).arg ( logFile ).toLocal8Bit ().constData () );
304
- #else
305
- setenv ( " QGIS_LOG_FILE" , logFile.toLocal8Bit ().constData (), 1 );
306
- #endif
311
+ time.start ();
312
+ printRequestInfos ();
307
313
}
308
314
309
- printRequestInfos (); // print request infos if in debug mode
310
-
311
315
// Request handler
312
316
QScopedPointer<QgsRequestHandler> theRequestHandler ( createRequestHandler () );
313
317
QMap<QString, QString> parameterMap;
@@ -317,11 +321,12 @@ int main( int argc, char * argv[] )
317
321
}
318
322
catch ( QgsMapServiceException& e )
319
323
{
320
- QgsDebugMsg ( " An exception was thrown during input parsing " );
324
+ QgsMessageLog::logMessage ( " Parse input exception: " + e. message (), " Server " , QgsMessageLog::CRITICAL );
321
325
theRequestHandler->sendServiceException ( e );
322
326
continue ;
323
327
}
324
328
329
+ printRequestParameters ( parameterMap, logLevel );
325
330
QMap<QString, QString>::const_iterator paramIt;
326
331
327
332
// Config file path
@@ -332,6 +337,7 @@ int main( int argc, char * argv[] )
332
337
paramIt = parameterMap.find ( " SERVICE" );
333
338
if ( paramIt == parameterMap.constEnd () )
334
339
{
340
+ QgsMessageLog::logMessage ( " Exception: SERVICE parameter is missing" , " Server" , QgsMessageLog::CRITICAL );
335
341
theRequestHandler->sendServiceException ( QgsMapServiceException ( " ServiceNotSpecified" , " Service not specified. The SERVICE parameter is mandatory" ) );
336
342
continue ;
337
343
}
@@ -345,7 +351,8 @@ int main( int argc, char * argv[] )
345
351
QgsWCSProjectParser* p = QgsConfigCache::instance ()->wcsConfiguration ( configFilePath );
346
352
if ( !p )
347
353
{
348
- // error handling
354
+ theRequestHandler->sendServiceException ( QgsMapServiceException ( " Project file error" , " Error reading the project file" ) );
355
+ continue ;
349
356
}
350
357
QgsWCSServer wcsServer ( configFilePath, parameterMap, p, theRequestHandler.take () );
351
358
wcsServer.executeRequest ();
@@ -355,7 +362,8 @@ int main( int argc, char * argv[] )
355
362
QgsWFSProjectParser* p = QgsConfigCache::instance ()->wfsConfiguration ( configFilePath );
356
363
if ( !p )
357
364
{
358
- // error handling
365
+ theRequestHandler->sendServiceException ( QgsMapServiceException ( " Project file error" , " Error reading the project file" ) );
366
+ continue ;
359
367
}
360
368
QgsWFSServer wfsServer ( configFilePath, parameterMap, p, theRequestHandler.take () );
361
369
wfsServer.executeRequest ();
@@ -365,12 +373,18 @@ int main( int argc, char * argv[] )
365
373
QgsWMSConfigParser* p = QgsConfigCache::instance ()->wmsConfiguration ( configFilePath, parameterMap );
366
374
if ( !p )
367
375
{
368
- // error handling
376
+ theRequestHandler->sendServiceException ( QgsMapServiceException ( " WMS configuration error" , " There was an error reading gthe project file or the SLD configuration" ) );
377
+ continue ;
369
378
}
370
379
// adminConfigParser->loadLabelSettings( theMapRenderer->labelingEngine() );
371
380
QgsWMSServer wmsServer ( configFilePath, parameterMap, p, theRequestHandler.take (), theMapRenderer.data (), &capabilitiesCache );
372
381
wmsServer.executeRequest ();
373
382
}
383
+
384
+ if ( logLevel < 1 )
385
+ {
386
+ QgsMessageLog::logMessage ( " Request finished in " + QString::number ( time.elapsed () ) + " ms" , " Server" , QgsMessageLog::INFO );
387
+ }
374
388
}
375
389
376
390
return 0 ;
0 commit comments