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