-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FEATURE]: Server logging also in release mode
- Loading branch information
Showing
5 changed files
with
181 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
/*************************************************************************** | ||
qgsserverlogger.cpp | ||
------------------- | ||
begin : May 5, 2014 | ||
copyright : (C) 2014 by Marco Hugentobler | ||
email : marco dot hugentobler at sourcepole dot ch | ||
***************************************************************************/ | ||
|
||
/*************************************************************************** | ||
* * | ||
* This program is free software; you can redistribute it and/or modify * | ||
* it under the terms of the GNU General Public License as published by * | ||
* the Free Software Foundation; either version 2 of the License, or * | ||
* (at your option) any later version. * | ||
* * | ||
***************************************************************************/ | ||
|
||
#include "qgsserverlogger.h" | ||
#include <QCoreApplication> | ||
#include <QFile> | ||
#include <QTextStream> | ||
#include <QTime> | ||
|
||
QgsServerLogger* QgsServerLogger::mInstance = 0; | ||
|
||
QgsServerLogger* QgsServerLogger::instance() | ||
{ | ||
if ( mInstance == 0 ) | ||
{ | ||
mInstance = new QgsServerLogger(); | ||
} | ||
return mInstance; | ||
} | ||
|
||
QgsServerLogger::QgsServerLogger(): mLogFile( 0 ) | ||
{ | ||
//logfile | ||
QString filePath = getenv( "QGIS_LOG_FILE" ); | ||
mLogFile.setFileName( filePath ); | ||
if ( mLogFile.open( QIODevice::Append ) ) | ||
{ | ||
mTextStream.setDevice( &mLogFile ); | ||
} | ||
|
||
//log level | ||
char* logLevelChar = getenv( "QGIS_LOG_LEVEL" ); | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong. |
||
if ( logLevelChar ) | ||
{ | ||
mLogLevel = atoi( logLevelChar ); | ||
} | ||
else | ||
{ | ||
mLogLevel = 3; | ||
} | ||
|
||
connect( QgsMessageLog::instance(), SIGNAL( messageReceived( QString, QString, QgsMessageLog::MessageLevel ) ), this, | ||
SLOT( logMessage( QString, QString, QgsMessageLog::MessageLevel ) ) ); | ||
} | ||
|
||
void QgsServerLogger::logMessage( QString message, QString tag, QgsMessageLog::MessageLevel level ) | ||
{ | ||
Q_UNUSED( tag ); | ||
if ( !mLogFile.isOpen() || mLogLevel > level ) | ||
{ | ||
return; | ||
} | ||
|
||
mTextStream << ( "[" + QString::number( qlonglong( QCoreApplication::applicationPid() ) ) + "][" | ||
+ QTime::currentTime().toString() + "] " + message + "\n" ); | ||
mTextStream.flush(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/*************************************************************************** | ||
qgsserverlogger.h | ||
----------------- | ||
begin : May 5, 2014 | ||
copyright : (C) 2014 by Marco Hugentobler | ||
email : marco dot hugentobler at sourcepole dot ch | ||
***************************************************************************/ | ||
|
||
/*************************************************************************** | ||
* * | ||
* This program is free software; you can redistribute it and/or modify * | ||
* it under the terms of the GNU General Public License as published by * | ||
* the Free Software Foundation; either version 2 of the License, or * | ||
* (at your option) any later version. * | ||
* * | ||
***************************************************************************/ | ||
|
||
#ifndef QGSSERVERLOGGER_H | ||
#define QGSSERVERLOGGER_H | ||
|
||
#include "qgsmessagelog.h" | ||
|
||
#include <QFile> | ||
#include <QObject> | ||
#include <QString> | ||
#include <QTextStream> | ||
|
||
/**Writes message log into server logfile*/ | ||
class QgsServerLogger: public QObject | ||
{ | ||
Q_OBJECT | ||
public: | ||
static QgsServerLogger* instance(); | ||
|
||
int logLevel() const { return mLogLevel; } | ||
//QString logFile() const { return mLogFile; } | ||
|
||
public slots: | ||
void logMessage( QString message, QString tag, QgsMessageLog::MessageLevel level ); | ||
|
||
protected: | ||
QgsServerLogger(); | ||
|
||
private: | ||
static QgsServerLogger* mInstance; | ||
|
||
QFile mLogFile; | ||
QTextStream mTextStream; | ||
int mLogLevel; | ||
}; | ||
|
||
#endif // QGSSERVERLOGGER_H |
@mhugent Hi. On Mac, using clang, I had to add:
Otherwise, the
getenv()
calls (here and at line # 38) were undefined, and the build threw errors. The fix worked for me, but figured you had a better idea on how to fix it, i.e. I won't do a commit unless you think it is OK.