Merge pull request #3141

3c28ece Logger: runtime log config, no logs till a user selects wallet mode (xiphon)
This commit is contained in:
luigi1111 2020-10-13 12:36:49 -05:00
commit 8c5891e28a
No known key found for this signature in database
GPG key ID: F4ACA0183641E010
8 changed files with 74 additions and 25 deletions

View file

@ -1367,6 +1367,7 @@ ApplicationWindow {
} else {
wizard.wizardState = "wizardHome";
rootItem.state = "normal"
logger.resetLogFilePath(persistentSettings.portable);
openWallet("wizard");
}

View file

@ -272,9 +272,9 @@ Rectangle {
<style type='text/css'>\
a {cursor:pointer;text-decoration: none; color: #FF6C3C}\
</style>\
<a href='#'>%1</a>".arg(walletLogPath)
<a href='#'>%1</a>".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)

View file

@ -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;
}

View file

@ -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;
};

View file

@ -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

View file

@ -191,7 +191,7 @@ QString MoneroSettings::portableFilePath() const
return filename;
}
QString MoneroSettings::portableFolderName() const
QString MoneroSettings::portableFolderName()
{
return "monero-storage";
}

View file

@ -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<QSettings> portableSettings() const;
std::unique_ptr<QSettings> unportableSettings() const;
void swap(std::unique_ptr<QSettings> newSettings);

View file

@ -48,6 +48,7 @@ Rectangle {
return;
}
logger.resetLogFilePath(portable);
appWindow.changeWalletMode(mode);
wizardController.wizardStackView.backTransition = false;
wizardController.wizardState = wizardState;