From 333df92c06a0f16177879b8ed5d8e851fe477a68 Mon Sep 17 00:00:00 2001 From: f4exb Date: Sun, 7 Jan 2018 02:52:35 +0100 Subject: [PATCH] Put application and system info at the start of the log file if it is being used --- logging/loggerwithfile.cpp | 7 +++++++ logging/loggerwithfile.h | 3 +++ sdrgui/mainwindow.cpp | 19 +++++++++++++++++++ sdrsrv/maincore.cpp | 20 ++++++++++++++++++++ 4 files changed, 49 insertions(+) diff --git a/logging/loggerwithfile.cpp b/logging/loggerwithfile.cpp index c09e250e0..c1534316c 100644 --- a/logging/loggerwithfile.cpp +++ b/logging/loggerwithfile.cpp @@ -48,6 +48,13 @@ void LoggerWithFile::log(const QtMsgType type, const QString& message, const QSt } } +void LoggerWithFile::logToFile(const QtMsgType type, const QString& message, const QString &file, const QString &function, const int line) +{ + if (fileLogger && useFileFlogger) { + fileLogger->log(type,message,file,function,line); + } +} + void LoggerWithFile::clear(const bool buffer, const bool variables) { consoleLogger->clear(buffer,variables); diff --git a/logging/loggerwithfile.h b/logging/loggerwithfile.h index 29143115f..526e28df7 100644 --- a/logging/loggerwithfile.h +++ b/logging/loggerwithfile.h @@ -74,6 +74,9 @@ public: void getFileMinMessageLevelStr(QString& levelStr); void getLogFileName(QString& fileName); + /** This will log to file only */ + void logToFile(const QtMsgType type, const QString& message, const QString &file="", const QString &function="", const int line=0); + private: /** First console logger */ Logger* consoleLogger; diff --git a/sdrgui/mainwindow.cpp b/sdrgui/mainwindow.cpp index 11aa8c691..ce5da9501 100644 --- a/sdrgui/mainwindow.cpp +++ b/sdrgui/mainwindow.cpp @@ -1725,6 +1725,25 @@ void MainWindow::setLoggingOptions() } m_logger->setUseFileLogger(m_settings.getUseLogFile()); + + if (m_settings.getUseLogFile()) + { +#if QT_VERSION >= 0x050400 + QString appInfoStr(tr("%1 v%2 Qt %3 %4 %5") + .arg(qApp->applicationName()) + .arg(qApp->applicationVersion()) + .arg(QT_VERSION_STR) + .arg(QSysInfo::currentCpuArchitecture()) + .arg(QSysInfo::prettyProductName())); +#else + QString appInfoStr(tr("%1 v%2 Qt %3") + .arg(qApp->applicationName()) + .arg(qApp->applicationVersion()) + .arg(QT_VERSION_STR)); + #endif + + m_logger->logToFile(QtInfoMsg, appInfoStr); + } } void MainWindow::focusHasChanged(QWidget *oldWidget __attribute__((unused)), QWidget *newWidget) diff --git a/sdrsrv/maincore.cpp b/sdrsrv/maincore.cpp index 12afea660..a7a10e7d3 100644 --- a/sdrsrv/maincore.cpp +++ b/sdrsrv/maincore.cpp @@ -17,6 +17,7 @@ /////////////////////////////////////////////////////////////////////////////////// #include +#include #include #include "dsp/dspengine.h" @@ -216,6 +217,25 @@ void MainCore::setLoggingOptions() } m_logger->setUseFileLogger(m_settings.getUseLogFile()); + + if (m_settings.getUseLogFile()) + { +#if QT_VERSION >= 0x050400 + QString appInfoStr(tr("%1 v%2 Qt %3 %4 %5") + .arg(QCoreApplication::instance()->applicationName()) + .arg(QCoreApplication::instance()->applicationVersion()) + .arg(QT_VERSION_STR) + .arg(QSysInfo::currentCpuArchitecture()) + .arg(QSysInfo::prettyProductName())); +#else + QString appInfoStr(tr("%1 v%2 Qt %3") + .arg(QCoreApplication::instance()->applicationName()) + .arg(QCoreApplication::instance()->applicationVersion()) + .arg(QT_VERSION_STR)); +#endif + + m_logger->logToFile(QtInfoMsg, appInfoStr); + } } void MainCore::addSinkDevice()