Merge pull request #1358

341ac18 log qt/qml to easylogging, add --log-file cmdline option
92582a9 delete unused WalletManager functions
c9daab7 don't use cmdline arguments as daemon arguments
7283fe4 use qWarning/qCritical on QrCodeScanner info/errors
15155f2 print logs on console
pull/2/head
luigi1111 6 years ago
commit 4c2640d4b3
No known key found for this signature in database
GPG Key ID: F4ACA0183641E010

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

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

@ -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(), true);
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,9 +220,11 @@ 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();
const QStringList arguments = (QStringList) QCoreApplication::arguments().at(0);
DaemonManager * daemonManager = DaemonManager::instance(&arguments);
engine.rootContext()->setContextProperty("daemonManager", daemonManager);
#endif
@ -289,13 +294,13 @@ int main(int argc, char *argv[])
QObject *qmlCamera = rootObject->findChild<QObject*>("qrCameraQML");
if (qmlCamera)
{
qDebug() << "QrCodeScanner : object found";
qWarning() << "QrCodeScanner : object found";
QCamera *camera_ = qvariant_cast<QCamera*>(qmlCamera->property("mediaObject"));
QObject *qmlFinder = rootObject->findChild<QObject*>("QrFinder");
qobject_cast<QrCodeScanner*>(qmlFinder)->setSource(camera_);
}
else
qDebug() << "QrCodeScanner : something went wrong !";
qCritical() << "QrCodeScanner : something went wrong !";
#endif
QObject::connect(eventFilter, SIGNAL(sequencePressed(QVariant,QVariant)), rootObject, SLOT(sequencePressed(QVariant,QVariant)));

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

@ -377,26 +377,6 @@ bool WalletManager::clearWalletCache(const QString &wallet_path) const
return walletCache.rename(newFileName);
}
void WalletManager::debug(const QString &s)
{
Monero::Wallet::debug("qml", s.toStdString());
}
void WalletManager::info(const QString &s)
{
Monero::Wallet::info("qml", s.toStdString());
}
void WalletManager::warning(const QString &s)
{
Monero::Wallet::warning("qml", s.toStdString());
}
void WalletManager::error(const QString &s)
{
Monero::Wallet::error("qml", s.toStdString());
}
WalletManager::WalletManager(QObject *parent) : QObject(parent)
{
m_pimpl = Monero::WalletManagerFactory::getWalletManager();

@ -143,11 +143,6 @@ public:
// clear/rename wallet cache
Q_INVOKABLE bool clearWalletCache(const QString &fileName) const;
Q_INVOKABLE void debug(const QString &s);
Q_INVOKABLE void info(const QString &s);
Q_INVOKABLE void warning(const QString &s);
Q_INVOKABLE void error(const QString &s);
signals:
void walletOpened(Wallet * wallet);