diff --git a/loggingwindow.cpp b/loggingwindow.cpp index c9c6b67..e182223 100644 --- a/loggingwindow.cpp +++ b/loggingwindow.cpp @@ -1,7 +1,8 @@ #include "loggingwindow.h" #include "ui_loggingwindow.h" -loggingWindow::loggingWindow(QWidget *parent) : +loggingWindow::loggingWindow(QString logFile, QWidget *parent) : + logFilename(logFile), QWidget(parent), ui(new Ui::loggingWindow) { @@ -12,20 +13,15 @@ loggingWindow::loggingWindow(QWidget *parent) : ui->annotateBtn->setDefault(true); ui->logTextDisplay->setFocusPolicy(Qt::NoFocus); ui->annotateBtn->setFocusPolicy(Qt::NoFocus); + + QDir d = QFileInfo(logFilename).absoluteDir(); + logDirectory = d.absolutePath(); QFont font("Monospace"); font.setStyleHint(QFont::TypeWriter); ui->logTextDisplay->setFont(font); ui->userAnnotationText->setFont(font); -#ifdef Q_OS_MAC - logFilename = QStandardPaths::standardLocations(QStandardPaths::DownloadLocation)[0] + "/wfview.log"; - logDirectory = QStandardPaths::standardLocations(QStandardPaths::DownloadLocation)[0]; - -#else - logFilename= QStandardPaths::standardLocations(QStandardPaths::TempLocation)[0] + "/wfview.log"; - logDirectory = QStandardPaths::standardLocations(QStandardPaths::TempLocation)[0]; -#endif clipboard = QApplication::clipboard(); socket = new QTcpSocket(this); connect(socket, SIGNAL(connected()), this, SLOT(connectedToHost())); @@ -157,7 +153,7 @@ void loggingWindow::on_openDirBtn_clicked() #endif arg += QDir::toNativeSeparators(dir.canonicalFilePath());; rtn = QProcess::startDetached(cmd, arg); - if(!rtn) + if(rtn) qInfo(logLogger()) << "Error, open log directory" << logDirectory << "command failed"; } diff --git a/loggingwindow.h b/loggingwindow.h index de11348..24e7e4c 100644 --- a/loggingwindow.h +++ b/loggingwindow.h @@ -25,7 +25,7 @@ class loggingWindow : public QWidget Q_OBJECT public: - explicit loggingWindow(QWidget *parent = nullptr); + explicit loggingWindow(QString logFile, QWidget *parent = NULL); ~loggingWindow(); void acceptLogText(QString text); diff --git a/main.cpp b/main.cpp index e317348..d000415 100644 --- a/main.cpp +++ b/main.cpp @@ -74,10 +74,12 @@ int main(int argc, char *argv[]) QString serialPortCL; QString hostCL; QString civCL; + QDateTime date = QDateTime::currentDateTime(); + QString formattedTime = date.toString("dd.MM.yyyy hh:mm:ss"); #ifdef Q_OS_MAC - QString logFilename= QStandardPaths::standardLocations(QStandardPaths::DownloadLocation)[0] + "/wfview.log"; + QString logFilename = (QString("%1/%2-%3.log").arg(QStandardPaths::standardLocations(QStandardPaths::DownloadLocation)[0]).arg(a.applicationName()).arg(date.toString("yyyyMMddhhmmss"))); #else - QString logFilename= QStandardPaths::standardLocations(QStandardPaths::TempLocation)[0] + "/wfview.log"; + QString logFilename = (QString("%1/%2-%3.log").arg(QStandardPaths::standardLocations(QStandardPaths::TempLocation)[0]).arg(a.applicationName()).arg(date.toString("yyyyMMddhhmmss"))); #endif QString settingsFile = NULL; QString currentArg; @@ -185,10 +187,10 @@ int main(int argc, char *argv[]) signal(SIGTERM, cleanup); signal(SIGKILL, cleanup); #endif - w = new servermain(serialPortCL, hostCL, settingsFile); + w = new servermain(serialPortCL, hostCL, logFilename, settingsFile); #else a.setWheelScrollLines(1); // one line per wheel click - wfmain w(serialPortCL, hostCL, settingsFile, debugMode); + wfmain w(serialPortCL, hostCL, settingsFile, logFilename, debugMode); w.show(); #endif diff --git a/servermain.cpp b/servermain.cpp index c2942c5..9ef2aa8 100644 --- a/servermain.cpp +++ b/servermain.cpp @@ -8,7 +8,7 @@ // This code is copyright 2017-2020 Elliott H. Liggett // All rights reserved -servermain::servermain(const QString serialPortCL, const QString hostCL, const QString settingsFile) +servermain::servermain(const QString serialPortCL, const QString hostCL, const QString settingsFile, const QString logFile) { this->serialPortCL = serialPortCL; this->hostCL = hostCL; diff --git a/servermain.h b/servermain.h index 1b7e3a8..fead26d 100644 --- a/servermain.h +++ b/servermain.h @@ -46,7 +46,7 @@ class servermain : public QObject Q_OBJECT public: - servermain(const QString serialPortCL, const QString hostCL, const QString settingsFile); + servermain(const QString serialPortCL, const QString hostCL, const QString logFile, const QString settingsFile); QString serialPortCL; QString hostCL; ~servermain(); diff --git a/wfmain.cpp b/wfmain.cpp index 8b22eb7..b814bb8 100644 --- a/wfmain.cpp +++ b/wfmain.cpp @@ -20,7 +20,8 @@ bool debugModeLogging = true; bool debugModeLogging = false; #endif -wfmain::wfmain(const QString serialPortCL, const QString hostCL, const QString settingsFile, bool debugMode, QWidget *parent ) : +wfmain::wfmain(const QString serialPortCL, const QString hostCL, const QString settingsFile, const QString logFile, bool debugMode, QWidget *parent ) : + logFilename(logFile), QMainWindow(parent), ui(new Ui::wfmain) { @@ -39,7 +40,7 @@ wfmain::wfmain(const QString serialPortCL, const QString hostCL, const QString s setWindowTitle(QString("wfview")); - logWindow = new loggingWindow(); + logWindow = new loggingWindow(logFile); initLogging(); logWindow->setInitialDebugState(debugMode); qInfo(logSystem()) << version; @@ -7091,11 +7092,6 @@ void wfmain::on_showLogBtn_clicked() void wfmain::initLogging() { -#ifdef Q_OS_MAC - logFilename= QStandardPaths::standardLocations(QStandardPaths::DownloadLocation)[0] + "/wfview.log"; -#else - logFilename= QStandardPaths::standardLocations(QStandardPaths::TempLocation)[0] + "/wfview.log"; -#endif // Set the logging file before doing anything else. m_logFile.reset(new QFile(logFilename)); // Open the file logging diff --git a/wfmain.h b/wfmain.h index f4ff6a2..95f5f84 100644 --- a/wfmain.h +++ b/wfmain.h @@ -64,7 +64,7 @@ class wfmain : public QMainWindow Q_OBJECT public: - explicit wfmain(const QString serialPortCL, const QString hostCL, const QString settingsFile, bool debugMode, QWidget *parent = 0); + explicit wfmain(const QString serialPortCL, const QString hostCL, const QString settingsFile, const QString logFile, bool debugMode, QWidget *parent = 0); QString serialPortCL; QString hostCL; ~wfmain();