feat(logging): log qt messages into logger, rather than into terminal
This commit is contained in:
parent
5564fddc21
commit
66d3f80073
1 changed files with 24 additions and 2 deletions
|
@ -1,11 +1,15 @@
|
||||||
#include "mainwindow.h"
|
#include "mainwindow.h"
|
||||||
#include "./ui_mainwindow.h"
|
#include "./ui_mainwindow.h"
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
|
#include "logger.h"
|
||||||
#include "objects/snap.h"
|
#include "objects/snap.h"
|
||||||
|
#include <map>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <qclipboard.h>
|
#include <qclipboard.h>
|
||||||
|
#include <qglobal.h>
|
||||||
#include <qmessagebox.h>
|
#include <qmessagebox.h>
|
||||||
#include <qmimedata.h>
|
#include <qmimedata.h>
|
||||||
|
#include <qstylefactory.h>
|
||||||
#include <qstylehints.h>
|
#include <qstylehints.h>
|
||||||
|
|
||||||
#ifdef _NDEBUG
|
#ifdef _NDEBUG
|
||||||
|
@ -27,7 +31,23 @@ inline bool isDarkMode() {
|
||||||
return text.lightness() > window.lightness();
|
return text.lightness() > window.lightness();
|
||||||
#endif // QT_VERSION
|
#endif // QT_VERSION
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QtMessageHandler defaultMessageHandler = nullptr;
|
||||||
|
|
||||||
|
std::map<QtMsgType, Logger::LogLevel> QT_MESSAGE_TYPE_TO_LOG_LEVEL = {
|
||||||
|
{ QtMsgType::QtInfoMsg, Logger::LogLevel::INFO },
|
||||||
|
{ QtMsgType::QtSystemMsg, Logger::LogLevel::INFO },
|
||||||
|
{ QtMsgType::QtDebugMsg, Logger::LogLevel::DEBUG },
|
||||||
|
{ QtMsgType::QtWarningMsg, Logger::LogLevel::WARNING },
|
||||||
|
{ QtMsgType::QtCriticalMsg, Logger::LogLevel::ERROR },
|
||||||
|
{ QtMsgType::QtFatalMsg, Logger::LogLevel::FATAL_ERROR },
|
||||||
|
};
|
||||||
|
|
||||||
|
void logQtMessage(QtMsgType type, const QMessageLogContext &context, const QString &msg) {
|
||||||
|
Logger::log("[Qt] " + msg.toStdString(), QT_MESSAGE_TYPE_TO_LOG_LEVEL[type]);
|
||||||
|
|
||||||
|
// if (defaultMessageHandler) defaultMessageHandler(type, context, msg);
|
||||||
|
}
|
||||||
|
|
||||||
MainWindow::MainWindow(QWidget *parent)
|
MainWindow::MainWindow(QWidget *parent)
|
||||||
: QMainWindow(parent)
|
: QMainWindow(parent)
|
||||||
|
@ -45,7 +65,9 @@ MainWindow::MainWindow(QWidget *parent)
|
||||||
QIcon::setFallbackThemeName("editor-dark");
|
QIcon::setFallbackThemeName("editor-dark");
|
||||||
else
|
else
|
||||||
QIcon::setFallbackThemeName("editor");
|
QIcon::setFallbackThemeName("editor");
|
||||||
|
|
||||||
|
// qApp->setStyle(QStyleFactory::create("fusion"));
|
||||||
|
defaultMessageHandler = qInstallMessageHandler(logQtMessage);
|
||||||
|
|
||||||
setCorner(Qt::BottomRightCorner, Qt::RightDockWidgetArea);
|
setCorner(Qt::BottomRightCorner, Qt::RightDockWidgetArea);
|
||||||
setCorner(Qt::BottomLeftCorner, Qt::LeftDockWidgetArea);
|
setCorner(Qt::BottomLeftCorner, Qt::LeftDockWidgetArea);
|
||||||
|
|
Loading…
Add table
Reference in a new issue