diff --git a/SConstruct b/SConstruct index f5be10f06..49f3f974d 100644 --- a/SConstruct +++ b/SConstruct @@ -319,7 +319,8 @@ qt_flags = [ "-DQT_QUICK_LIB", "-DQT_QUICKWIDGETS_LIB", "-DQT_QML_LIB", - "-DQT_CORE_LIB" + "-DQT_CORE_LIB", + "-DQT_MESSAGELOGCONTEXT", ] qt_env['CXXFLAGS'] += qt_flags qt_env['LIBPATH'] += ['#selfdrive/ui'] diff --git a/selfdrive/ui/main.cc b/selfdrive/ui/main.cc index 901899e39..35268bd88 100644 --- a/selfdrive/ui/main.cc +++ b/selfdrive/ui/main.cc @@ -7,6 +7,7 @@ #include "selfdrive/ui/qt/window.h" int main(int argc, char *argv[]) { + qInstallMessageHandler(swagLogMessageHandler); setQtSurfaceFormat(); if (Hardware::EON()) { diff --git a/selfdrive/ui/qt/onroad.cc b/selfdrive/ui/qt/onroad.cc index c321e7ebe..296f063e8 100644 --- a/selfdrive/ui/qt/onroad.cc +++ b/selfdrive/ui/qt/onroad.cc @@ -1,6 +1,7 @@ #include "selfdrive/ui/qt/onroad.h" #include +#include #include "selfdrive/common/swaglog.h" #include "selfdrive/common/timing.h" @@ -224,10 +225,10 @@ NvgWindow::~NvgWindow() { void NvgWindow::initializeGL() { initializeOpenGLFunctions(); - std::cout << "OpenGL version: " << glGetString(GL_VERSION) << std::endl; - std::cout << "OpenGL vendor: " << glGetString(GL_VENDOR) << std::endl; - std::cout << "OpenGL renderer: " << glGetString(GL_RENDERER) << std::endl; - std::cout << "OpenGL language version: " << glGetString(GL_SHADING_LANGUAGE_VERSION) << std::endl; + qInfo() << "OpenGL version:" << QString((const char*)glGetString(GL_VERSION)); + qInfo() << "OpenGL vendor:" << QString((const char*)glGetString(GL_VENDOR)); + qInfo() << "OpenGL renderer:" << QString((const char*)glGetString(GL_RENDERER)); + qInfo() << "OpenGL language version:" << QString((const char*)glGetString(GL_SHADING_LANGUAGE_VERSION)); ui_nvg_init(&QUIState::ui_state); prev_draw_t = millis_since_boot(); diff --git a/selfdrive/ui/qt/util.cc b/selfdrive/ui/qt/util.cc index b26ae371f..c077883d2 100644 --- a/selfdrive/ui/qt/util.cc +++ b/selfdrive/ui/qt/util.cc @@ -4,6 +4,7 @@ #include #include "selfdrive/common/params.h" +#include "selfdrive/common/swaglog.h" QString getBrand() { return Params().getBool("Passive") ? "dashcam" : "openpilot"; @@ -79,3 +80,22 @@ void ClickableWidget::paintEvent(QPaintEvent *) { QPainter p(this); style()->drawPrimitive(QStyle::PE_Widget, &opt, &p, this); } + + +void swagLogMessageHandler(QtMsgType type, const QMessageLogContext &context, const QString &msg) { + static std::map levels = { + {QtMsgType::QtDebugMsg, 10}, + {QtMsgType::QtInfoMsg, 20}, + {QtMsgType::QtWarningMsg, 30}, + {QtMsgType::QtCriticalMsg, 40}, + {QtMsgType::QtSystemMsg, 40}, + {QtMsgType::QtFatalMsg, 50}, + }; + + std::string file, function; + if (context.file != nullptr) file = context.file; + if (context.function != nullptr) function = context.function; + + auto bts = msg.toUtf8(); + cloudlog_e(levels[type], file.c_str(), context.line, function.c_str(), "%s", bts.constData()); +} diff --git a/selfdrive/ui/qt/util.h b/selfdrive/ui/qt/util.h index f56f640a3..6b9d4512b 100644 --- a/selfdrive/ui/qt/util.h +++ b/selfdrive/ui/qt/util.h @@ -13,6 +13,7 @@ void configFont(QPainter &p, const QString &family, int size, const QString &sty void clearLayout(QLayout* layout); void setQtSurfaceFormat(); QString timeAgo(const QDateTime &date); +void swagLogMessageHandler(QtMsgType type, const QMessageLogContext &context, const QString &msg); class ClickableWidget : public QWidget {