keep client version persistant (#2750)
This commit is contained in:
parent
f3f83882e0
commit
0a57229886
3 changed files with 19 additions and 11 deletions
|
@ -37,4 +37,5 @@ void DlgViewLog::logEntryAdded(QString message)
|
|||
void DlgViewLog::closeEvent(QCloseEvent * /* event */)
|
||||
{
|
||||
logArea->clear();
|
||||
logArea->appendPlainText(Logger::getInstance().getClientVersion());
|
||||
}
|
|
@ -1,14 +1,15 @@
|
|||
#include "logger.h"
|
||||
|
||||
#include "version_string.h"
|
||||
#include <QDateTime>
|
||||
#include <iostream>
|
||||
|
||||
#define LOGGER_MAX_ENTRIES 128
|
||||
#define LOGGER_FILENAME "qdebug.txt"
|
||||
|
||||
Logger::Logger()
|
||||
: logToFileEnabled(false)
|
||||
Logger::Logger() : logToFileEnabled(false)
|
||||
{
|
||||
logBuffer.append(getClientVersion());
|
||||
std::cerr << getClientVersion().toStdString() << std::endl;
|
||||
}
|
||||
|
||||
Logger::~Logger()
|
||||
|
@ -19,27 +20,33 @@ Logger::~Logger()
|
|||
|
||||
void Logger::logToFile(bool enabled)
|
||||
{
|
||||
if(enabled)
|
||||
if (enabled)
|
||||
openLogfileSession();
|
||||
else
|
||||
closeLogfileSession();
|
||||
}
|
||||
|
||||
QString Logger::getClientVersion()
|
||||
{
|
||||
return "Client Version: " + QString::fromStdString(VERSION_STRING);
|
||||
}
|
||||
|
||||
void Logger::openLogfileSession()
|
||||
{
|
||||
if(logToFileEnabled)
|
||||
if (logToFileEnabled)
|
||||
return;
|
||||
|
||||
fileHandle.setFileName(LOGGER_FILENAME);
|
||||
fileHandle.open(QIODevice::WriteOnly | QIODevice::Truncate | QIODevice::Text);
|
||||
fileStream.setDevice(&fileHandle);
|
||||
fileStream << "Log session started at " << QDateTime::currentDateTime().toString() << endl;
|
||||
fileStream << getClientVersion() << endl;
|
||||
logToFileEnabled = true;
|
||||
}
|
||||
|
||||
void Logger::closeLogfileSession()
|
||||
{
|
||||
if(!logToFileEnabled)
|
||||
if (!logToFileEnabled)
|
||||
return;
|
||||
|
||||
logToFileEnabled = false;
|
||||
|
@ -47,12 +54,9 @@ void Logger::closeLogfileSession()
|
|||
fileHandle.close();
|
||||
}
|
||||
|
||||
|
||||
void Logger::log(QtMsgType /* type */, const QMessageLogContext & /* ctx */, const QString message)
|
||||
{
|
||||
QMetaObject::invokeMethod(this, "internalLog", Qt::QueuedConnection,
|
||||
Q_ARG(const QString &, message)
|
||||
);
|
||||
QMetaObject::invokeMethod(this, "internalLog", Qt::QueuedConnection, Q_ARG(const QString &, message));
|
||||
}
|
||||
|
||||
void Logger::internalLog(const QString message)
|
||||
|
@ -61,7 +65,9 @@ void Logger::internalLog(const QString message)
|
|||
|
||||
logBuffer.append(message);
|
||||
if (logBuffer.size() > LOGGER_MAX_ENTRIES)
|
||||
logBuffer.removeFirst();
|
||||
{
|
||||
logBuffer.removeAt(1);
|
||||
}
|
||||
|
||||
emit logEntryAdded(message);
|
||||
std::cerr << message.toStdString() << std::endl; // Print to stdout
|
||||
|
|
|
@ -30,6 +30,7 @@ private:
|
|||
public:
|
||||
void logToFile(bool enabled);
|
||||
void log(QtMsgType type, const QMessageLogContext &ctx, const QString message);
|
||||
QString getClientVersion();
|
||||
QList<QString> getLogBuffer() { return logBuffer; }
|
||||
protected:
|
||||
void openLogfileSession();
|
||||
|
|
Loading…
Reference in a new issue