mirror of
https://github.com/monero-project/monero-gui
synced 2025-01-06 19:26:23 +01:00
log qt/qml to easylogging, add --log-file cmdline option
This commit is contained in:
parent
7cea134352
commit
341ac18f1a
49
Logger.cpp
Normal file
49
Logger.cpp
Normal file
@ -0,0 +1,49 @@
|
||||
#include <QCoreApplication>
|
||||
#include <QStandardPaths>
|
||||
#include <QFileInfo>
|
||||
#include <QString>
|
||||
|
||||
#include "Logger.h"
|
||||
#include "wallet/api/wallet2_api.h"
|
||||
|
||||
// default log path by OS (should be writable)
|
||||
static const QString default_name = "monero-wallet-gui.log";
|
||||
#if defined(Q_OS_ANDROID) || defined(Q_OS_IOS)
|
||||
static const QString osPath = QStandardPaths::standardLocations(QStandardPaths::AppDataLocation).at(0);
|
||||
#elif defined(Q_OS_WIN)
|
||||
static const QString osPath = QCoreApplication::applicationDirPath();
|
||||
#elif defined(Q_OS_MAC)
|
||||
static const QString osPath = QStandardPaths::standardLocations(QStandardPaths::HomeLocation).at(0) + "/Library/Logs";
|
||||
#else // linux + bsd
|
||||
static const QString osPath = QStandardPaths::standardLocations(QStandardPaths::HomeLocation).at(0);
|
||||
#endif
|
||||
|
||||
|
||||
// return the absolute path of the logfile
|
||||
const QString getLogPath(const QString logPath)
|
||||
{
|
||||
const QFileInfo fi(logPath);
|
||||
|
||||
if(!logPath.isEmpty() && !fi.isDir())
|
||||
return fi.absoluteFilePath();
|
||||
else
|
||||
return osPath + "/" + default_name;
|
||||
}
|
||||
|
||||
|
||||
// custom messageHandler that foward all messages to easylogging
|
||||
void messageHandler(QtMsgType type, const QMessageLogContext &context, const QString &message)
|
||||
{
|
||||
(void) context; // context isn't used in release builds
|
||||
const std::string cat = "frontend"; // category displayed in the log
|
||||
const std::string msg = message.toStdString();
|
||||
switch(type)
|
||||
{
|
||||
case QtDebugMsg: Monero::Wallet::debug(cat, msg); break;
|
||||
case QtInfoMsg: Monero::Wallet::info(cat, msg); break;
|
||||
case QtWarningMsg: Monero::Wallet::warning(cat, msg); break;
|
||||
case QtCriticalMsg: Monero::Wallet::error(cat, msg); break;
|
||||
case QtFatalMsg: Monero::Wallet::error(cat, msg); break;
|
||||
}
|
||||
}
|
||||
|
8
Logger.h
Normal file
8
Logger.h
Normal file
@ -0,0 +1,8 @@
|
||||
#ifndef LOGGER_H
|
||||
#define LOGGER_H
|
||||
|
||||
const QString getLogPath(const QString logPath);
|
||||
void messageHandler(QtMsgType type, const QMessageLogContext &context, const QString &message);
|
||||
|
||||
#endif // LOGGER_H
|
||||
|
23
main.cpp
23
main.cpp
@ -54,6 +54,7 @@
|
||||
#include "Subaddress.h"
|
||||
#include "model/SubaddressModel.h"
|
||||
#include "wallet/api/wallet2_api.h"
|
||||
#include "Logger.h"
|
||||
#include "MainApp.h"
|
||||
|
||||
// IOS exclusions
|
||||
@ -70,12 +71,6 @@ bool isAndroid = false;
|
||||
bool isWindows = false;
|
||||
bool isDesktop = false;
|
||||
|
||||
void messageHandler(QtMsgType type, const QMessageLogContext &context, const QString &msg)
|
||||
{
|
||||
// Send all message types to logger
|
||||
Monero::Wallet::debug("qml", msg.toStdString());
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
// platform dependant settings
|
||||
@ -117,16 +112,24 @@ int main(int argc, char *argv[])
|
||||
app.installEventFilter(eventFilter);
|
||||
|
||||
QCommandLineParser parser;
|
||||
QCommandLineOption logPathOption(QStringList() << "l" << "log-file",
|
||||
QCoreApplication::translate("main", "Log to specified file"),
|
||||
QCoreApplication::translate("main", "file"));
|
||||
parser.addOption(logPathOption);
|
||||
parser.addHelpOption();
|
||||
parser.process(app);
|
||||
|
||||
Monero::Utils::onStartup();
|
||||
|
||||
// Log settings
|
||||
Monero::Wallet::init(argv[0], "monero-wallet-gui");
|
||||
// qInstallMessageHandler(messageHandler);
|
||||
const QString logPath = getLogPath(parser.value(logPathOption));
|
||||
Monero::Wallet::init(argv[0], "monero-wallet-gui", logPath.toStdString().c_str());
|
||||
qInstallMessageHandler(messageHandler);
|
||||
|
||||
qDebug() << "app startd";
|
||||
|
||||
// loglevel is configured in main.qml. Anything lower than
|
||||
// qWarning is not shown here.
|
||||
qWarning().noquote() << "app startd" << "(log: " + logPath + ")";
|
||||
|
||||
// screen settings
|
||||
// Mobile is designed on 128dpi
|
||||
@ -217,6 +220,8 @@ int main(int argc, char *argv[])
|
||||
|
||||
engine.rootContext()->setContextProperty("qtRuntimeVersion", qVersion());
|
||||
|
||||
engine.rootContext()->setContextProperty("walletLogPath", logPath);
|
||||
|
||||
// Exclude daemon manager from IOS
|
||||
#ifndef Q_OS_IOS
|
||||
const QStringList arguments = QCoreApplication::arguments();
|
||||
|
@ -45,6 +45,7 @@ HEADERS += \
|
||||
src/libwalletqt/Subaddress.h \
|
||||
src/zxcvbn-c/zxcvbn.h \
|
||||
src/libwalletqt/UnsignedTransaction.h \
|
||||
Logger.h \
|
||||
MainApp.h
|
||||
|
||||
SOURCES += main.cpp \
|
||||
@ -70,6 +71,7 @@ SOURCES += main.cpp \
|
||||
src/libwalletqt/Subaddress.cpp \
|
||||
src/zxcvbn-c/zxcvbn.c \
|
||||
src/libwalletqt/UnsignedTransaction.cpp \
|
||||
Logger.cpp \
|
||||
MainApp.cpp
|
||||
|
||||
CONFIG(DISABLE_PASS_STRENGTH_METER) {
|
||||
|
@ -730,13 +730,13 @@ Rectangle {
|
||||
TextBlock {
|
||||
Layout.fillWidth: true
|
||||
font.pixelSize: 14
|
||||
text: (!currentWallet) ? "" : qsTr("Wallet log path: ") + translationManager.emptyString
|
||||
text: qsTr("Wallet log path: ") + translationManager.emptyString
|
||||
}
|
||||
|
||||
TextBlock {
|
||||
Layout.fillWidth: true
|
||||
font.pixelSize: 14
|
||||
text: currentWallet.walletLogPath + translationManager.emptyString
|
||||
text: walletLogPath
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -722,17 +722,6 @@ QString Wallet::getDaemonLogPath() const
|
||||
return QString::fromStdString(m_walletImpl->getDefaultDataDir()) + "/bitmonero.log";
|
||||
}
|
||||
|
||||
QString Wallet::getWalletLogPath() const
|
||||
{
|
||||
const QString filename("monero-wallet-gui.log");
|
||||
|
||||
#ifdef Q_OS_MACOS
|
||||
return QStandardPaths::standardLocations(QStandardPaths::HomeLocation).at(0) + "/Library/Logs/" + filename;
|
||||
#else
|
||||
return QCoreApplication::applicationDirPath() + "/" + filename;
|
||||
#endif
|
||||
}
|
||||
|
||||
bool Wallet::blackballOutput(const QString &pubkey)
|
||||
{
|
||||
QList<QString> list;
|
||||
|
@ -50,7 +50,6 @@ class Wallet : public QObject
|
||||
Q_PROPERTY(QString secretSpendKey READ getSecretSpendKey)
|
||||
Q_PROPERTY(QString publicSpendKey READ getPublicSpendKey)
|
||||
Q_PROPERTY(QString daemonLogPath READ getDaemonLogPath CONSTANT)
|
||||
Q_PROPERTY(QString walletLogPath READ getWalletLogPath CONSTANT)
|
||||
Q_PROPERTY(quint64 walletCreationHeight READ getWalletCreationHeight WRITE setWalletCreationHeight NOTIFY walletCreationHeightChanged)
|
||||
|
||||
public:
|
||||
|
Loading…
Reference in New Issue
Block a user