Skip to content
Permalink
Browse files

QgsServerLogger cleanup

  • Loading branch information
Hugo Mercier
Hugo Mercier committed Dec 14, 2016
1 parent a8b9723 commit 64b131ce96bd4ee57bf8746c1e910ed5467b9015
Showing with 36 additions and 13 deletions.
  1. +3 −1 src/core/qgsmessagelog.h
  2. +5 −5 src/server/qgsserver.cpp
  3. +9 −2 src/server/qgsserver.h
  4. +2 −2 src/server/qgsserverlogger.cpp
  5. +17 −3 src/server/qgsserverlogger.h
@@ -37,9 +37,11 @@ class CORE_EXPORT QgsMessageLog : public QObject

enum MessageLevel
{
ALL = 0,
INFO = 0,
WARNING = 1,
CRITICAL = 2
CRITICAL = 2,
NONE = 3
};

//! add a message to the instance (and create it if necessary)
@@ -179,9 +179,9 @@ QFileInfo QgsServer::defaultProjectFile()
* @param parameterMap
* @param logLevel
*/
void QgsServer::printRequestParameters( const QMap< QString, QString>& parameterMap, int logLevel )
void QgsServer::printRequestParameters( const QMap< QString, QString>& parameterMap, QgsMessageLog::MessageLevel logLevel )
{
if ( logLevel > 0 )
if ( logLevel > QgsMessageLog::INFO )
{
return;
}
@@ -434,13 +434,13 @@ QPair<QByteArray, QByteArray> QgsServer::handleRequest( const QString& queryStri
if ( ! queryString.isEmpty() )
putenv( QStringLiteral( "QUERY_STRING" ), queryString );

int logLevel = QgsServerLogger::instance()->logLevel();
QgsMessageLog::MessageLevel logLevel = QgsServerLogger::instance()->logLevel();
QTime time; //used for measuring request time if loglevel < 1
QgsProject::instance()->removeAllMapLayers();

qApp->processEvents();

if ( logLevel < 1 )
if ( logLevel == QgsMessageLog::INFO )
{
time.start();
printRequestInfos();
@@ -614,7 +614,7 @@ QPair<QByteArray, QByteArray> QgsServer::handleRequest( const QString& queryStri

theRequestHandler->sendResponse();

if ( logLevel < 1 )
if ( logLevel == QgsMessageLog::INFO )
{
QgsMessageLog::logMessage( "Request finished in " + QString::number( time.elapsed() ) + " ms", QStringLiteral( "Server" ), QgsMessageLog::INFO );
}
@@ -33,6 +33,7 @@
#include "qgsconfigcache.h"
#include "qgscapabilitiescache.h"
#include "qgsmapsettings.h"
#include "qgsmessagelog.h"

#ifdef HAVE_SERVER_PYTHON_PLUGINS
#include "qgsserverplugins.h"
@@ -105,10 +106,16 @@ class SERVER_EXPORT QgsServer
static void dummyMessageHandler( QtMsgType type, const char *msg );
// Mainly for debug
static void printRequestInfos();
// Mainly for debug

/**
* @brief QgsServer::printRequestParameters prints the request parameters
* @param parameterMap
* @param logLevel
*/
static void printRequestParameters(
const QMap< QString, QString>& parameterMap,
int logLevel );
QgsMessageLog::MessageLevel logLevel );

static QFileInfo defaultProjectFile();
static QFileInfo defaultAdminSLD();
static void setupNetworkAccessManager();
@@ -36,7 +36,7 @@ QgsServerLogger* QgsServerLogger::instance()

QgsServerLogger::QgsServerLogger()
: mLogFile( nullptr )
, mLogLevel( 3 )
, mLogLevel( QgsMessageLog::NONE )
{
//logfile
QString filePath = getenv( "QGIS_SERVER_LOG_FILE" );
@@ -53,7 +53,7 @@ QgsServerLogger::QgsServerLogger()
char* logLevelChar = getenv( "QGIS_SERVER_LOG_LEVEL" );
if ( logLevelChar )
{
mLogLevel = atoi( logLevelChar );
mLogLevel = static_cast<QgsMessageLog::MessageLevel>( atoi( logLevelChar ) );
}

connect( QgsMessageLog::instance(), SIGNAL( messageReceived( QString, QString, QgsMessageLog::MessageLevel ) ), this,
@@ -30,12 +30,26 @@ class QgsServerLogger: public QObject
{
Q_OBJECT
public:

/**
* Get the singleton instance
*/
static QgsServerLogger* instance();

int logLevel() const { return mLogLevel; }
//QString logFile() const { return mLogFile; }
/**
* Get the current log level
*/
QgsMessageLog::MessageLevel logLevel() const { return mLogLevel; }

public slots:

/**
* Log a message from the server context
*
* @param message the message
* @param tag tag of the message
* @param level log level of the message
*/
void logMessage( const QString& message, const QString& tag, QgsMessageLog::MessageLevel level );

protected:
@@ -46,7 +60,7 @@ class QgsServerLogger: public QObject

QFile mLogFile;
QTextStream mTextStream;
int mLogLevel;
QgsMessageLog::MessageLevel mLogLevel;
};

#endif // QGSSERVERLOGGER_H

0 comments on commit 64b131c

Please sign in to comment.
You can’t perform that action at this time.