diff --git a/main.qml b/main.qml
index 11aa93f3..3e4faa5a 100644
--- a/main.qml
+++ b/main.qml
@@ -1367,6 +1367,7 @@ ApplicationWindow {
} else {
wizard.wizardState = "wizardHome";
rootItem.state = "normal"
+ logger.resetLogFilePath(persistentSettings.portable);
openWallet("wizard");
}
diff --git a/pages/settings/SettingsInfo.qml b/pages/settings/SettingsInfo.qml
index c6bcd1fc..d005d681 100644
--- a/pages/settings/SettingsInfo.qml
+++ b/pages/settings/SettingsInfo.qml
@@ -272,9 +272,9 @@ Rectangle {
\
- %1".arg(walletLogPath)
+ %1".arg(logger.logFilePath)
textFormat: Text.RichText
- onLinkActivated: oshelper.openContainingFolder(walletLogPath)
+ onLinkActivated: oshelper.openContainingFolder(logger.logFilePath)
MouseArea {
anchors.fill: parent
@@ -397,7 +397,7 @@ Rectangle {
if(currentWallet)
data += currentWallet.walletCreationHeight;
- data += "\nWallet log path: " + walletLogPath;
+ data += "\nWallet log path: " + logger.logFilePath;
data += "\nWallet mode: " + walletModeString;
data += "\nGraphics mode: " + isOpenGL ? "OpenGL" : "Low graphics mode";
if (isTails)
diff --git a/src/main/Logger.cpp b/src/main/Logger.cpp
index 0d15b4e3..228679d5 100644
--- a/src/main/Logger.cpp
+++ b/src/main/Logger.cpp
@@ -26,6 +26,8 @@
// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+#include "Logger.h"
+
#include
#include
#include
@@ -33,9 +35,11 @@
#include
#include
-#include "Logger.h"
+#include
+#include
+
+#include "qt/MoneroSettings.h"
#include "qt/TailsOS.h"
-#include "wallet/api/wallet2_api.h"
// default log path by OS (should be writable)
static const QString defaultLogName = "monero-wallet-gui.log";
@@ -63,15 +67,21 @@ static const QString defaultLogName = "monero-wallet-gui.log";
// return the absolute path of the logfile and ensure path folder exists
-const QString getLogPath(const QString logPath)
+const QString getLogPath(const QString &userDefinedLogFilePath, bool portable)
{
- const QFileInfo fi(logPath);
+ const QFileInfo fi(userDefinedLogFilePath);
+ if (!userDefinedLogFilePath.isEmpty() && !fi.isDir())
+ {
+ return fi.absoluteFilePath();
+ }
+
+ if (portable)
+ {
+ return QDir(MoneroSettings::portableFolderName()).filePath(defaultLogName);
+ }
if(TailsOS::detect() && TailsOS::usePersistence)
return QDir::homePath() + "/Persistent/Monero/logs/" + defaultLogName;
-
- if(!logPath.isEmpty() && !fi.isDir())
- return fi.absoluteFilePath();
else {
QDir appDir(osPath + "/" + appFolder);
if(!appDir.exists())
@@ -98,3 +108,26 @@ void messageHandler(QtMsgType type, const QMessageLogContext &context, const QSt
}
}
+Logger::Logger(QCoreApplication &parent, QString userDefinedLogFilePath)
+ : QObject(&parent)
+ , m_applicationFilePath(parent.applicationFilePath().toStdString())
+ , m_userDefinedLogFilePath(std::move(userDefinedLogFilePath))
+{
+ el::Configurations c;
+ c.setGlobally(el::ConfigurationType::ToFile, "false");
+ c.setGlobally(el::ConfigurationType::ToStandardOutput, "true");
+ el::Loggers::setDefaultConfigurations(c, true);
+}
+
+void Logger::resetLogFilePath(bool portable)
+{
+ m_logFilePath = QDir::toNativeSeparators(getLogPath(m_userDefinedLogFilePath, portable));
+ Monero::Wallet::init(m_applicationFilePath.c_str(), "monero-wallet-gui", m_logFilePath.toStdString(), true);
+ qInstallMessageHandler(messageHandler);
+ emit logFilePathChanged();
+}
+
+QString Logger::logFilePath() const
+{
+ return m_logFilePath;
+}
diff --git a/src/main/Logger.h b/src/main/Logger.h
index 7674a437..6d350ae8 100644
--- a/src/main/Logger.h
+++ b/src/main/Logger.h
@@ -26,11 +26,28 @@
// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-#ifndef LOGGER_H
-#define LOGGER_H
+#pragma once
-const QString getLogPath(const QString logPath);
-void messageHandler(QtMsgType type, const QMessageLogContext &context, const QString &message);
+#include
+#include
+#include
-#endif // LOGGER_H
+class Logger : public QObject
+{
+ Q_OBJECT
+ Q_PROPERTY(QString logFilePath READ logFilePath NOTIFY logFilePathChanged)
+public:
+ Logger(QCoreApplication &parent, QString userDefinedLogFilePath);
+
+ Q_INVOKABLE void resetLogFilePath(bool portable);
+ QString logFilePath() const;
+
+signals:
+ void logFilePathChanged() const;
+
+private:
+ const std::string m_applicationFilePath;
+ QString m_logFilePath;
+ const QString m_userDefinedLogFilePath;
+};
diff --git a/src/main/main.cpp b/src/main/main.cpp
index 90bd5106..e13c6198 100644
--- a/src/main/main.cpp
+++ b/src/main/main.cpp
@@ -61,7 +61,6 @@
#include "model/SubaddressModel.h"
#include "SubaddressAccount.h"
#include "model/SubaddressAccountModel.h"
-#include "wallet/api/wallet2_api.h"
#include "Logger.h"
#include "MainApp.h"
#include "qt/downloader.h"
@@ -269,10 +268,7 @@ Verify update binary using 'shasum'-compatible (SHA256 algo) output signed by tw
Monero::Utils::onStartup();
- // Log settings
- const QString logPath = QDir::toNativeSeparators(getLogPath(parser.value(logPathOption)));
- Monero::Wallet::init(argv[0], "monero-wallet-gui", logPath.toStdString().c_str(), true);
- qInstallMessageHandler(messageHandler);
+ Logger logger(app, parser.value(logPathOption));
// loglevel is configured in main.qml. Anything lower than
// qWarning is not shown here unless MONERO_LOG_LEVEL env var is set
@@ -281,7 +277,7 @@ Verify update binary using 'shasum'-compatible (SHA256 algo) output signed by tw
if (logLevelOk && logLevel >= 0 && logLevel <= Monero::WalletManagerFactory::LogLevel_Max){
Monero::WalletManagerFactory::setLogLevel(logLevel);
}
- qWarning().noquote() << "app startd" << "(log: " + logPath + ")";
+ qWarning().noquote() << "app startd" << "(log: " + logger.logFilePath() + ")";
if (parser.isSet(verifyUpdateOption))
{
@@ -446,14 +442,14 @@ Verify update binary using 'shasum'-compatible (SHA256 algo) output signed by tw
engine.addImageProvider(QLatin1String("qrcode"), new QRCodeImageProvider());
+ engine.rootContext()->setContextProperty("logger", &logger);
+
engine.rootContext()->setContextProperty("mainApp", &app);
engine.rootContext()->setContextProperty("IPC", ipc);
engine.rootContext()->setContextProperty("qtRuntimeVersion", qVersion());
- engine.rootContext()->setContextProperty("walletLogPath", logPath);
-
engine.rootContext()->setContextProperty("tailsUsePersistence", TailsOS::usePersistence);
// Exclude daemon manager from IOS
diff --git a/src/qt/MoneroSettings.cpp b/src/qt/MoneroSettings.cpp
index 1ee5eb40..bcd358e0 100644
--- a/src/qt/MoneroSettings.cpp
+++ b/src/qt/MoneroSettings.cpp
@@ -191,7 +191,7 @@ QString MoneroSettings::portableFilePath() const
return filename;
}
-QString MoneroSettings::portableFolderName() const
+QString MoneroSettings::portableFolderName()
{
return "monero-storage";
}
diff --git a/src/qt/MoneroSettings.h b/src/qt/MoneroSettings.h
index 3f822530..30f4b35b 100644
--- a/src/qt/MoneroSettings.h
+++ b/src/qt/MoneroSettings.h
@@ -63,6 +63,8 @@ public:
Q_INVOKABLE bool setPortable(bool enabled);
Q_INVOKABLE void setWritable(bool enabled);
+ static QString portableFolderName();
+
public slots:
void _q_propertyChanged();
@@ -84,7 +86,6 @@ private:
bool portable() const;
bool portableConfigExists() const;
QString portableFilePath() const;
- QString portableFolderName() const;
std::unique_ptr portableSettings() const;
std::unique_ptr unportableSettings() const;
void swap(std::unique_ptr newSettings);
diff --git a/wizard/WizardModeSelection.qml b/wizard/WizardModeSelection.qml
index 0a8b4d90..39fac9a2 100644
--- a/wizard/WizardModeSelection.qml
+++ b/wizard/WizardModeSelection.qml
@@ -48,6 +48,7 @@ Rectangle {
return;
}
+ logger.resetLogFilePath(portable);
appWindow.changeWalletMode(mode);
wizardController.wizardStackView.backTransition = false;
wizardController.wizardState = wizardState;