aboutsummaryrefslogtreecommitdiff
path: root/src/main
diff options
context:
space:
mode:
authorxiphon <xiphon@protonmail.com>2020-10-08 15:52:34 +0000
committerxiphon <xiphon@protonmail.com>2020-10-08 18:28:07 +0000
commit3c28ecef93949224f68d301f71d47296cc67e2f5 (patch)
treef23df1eae23ebbadcc9e8f138108e039366f14db /src/main
parentd3943ca2a9e1fa27ec9141ed94e1d4fb530aca31 (diff)
downloadmonzero-gui-3c28ecef93949224f68d301f71d47296cc67e2f5.tar.gz
monzero-gui-3c28ecef93949224f68d301f71d47296cc67e2f5.tar.xz
monzero-gui-3c28ecef93949224f68d301f71d47296cc67e2f5.zip
Logger: runtime log config, no logs till a user selects wallet mode
Diffstat (limited to 'src/main')
-rw-r--r--src/main/Logger.cpp47
-rw-r--r--src/main/Logger.h27
-rw-r--r--src/main/main.cpp12
3 files changed, 66 insertions, 20 deletions
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 <QCoreApplication>
#include <QStandardPaths>
#include <QFileInfo>
@@ -33,9 +35,11 @@
#include <QDir>
#include <QDebug>
-#include "Logger.h"
+#include <easylogging++.h>
+#include <wallet/api/wallet2_api.h>
+
+#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 <QCoreApplication>
+#include <QObject>
+#include <QString>
-#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