diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index e3c199e5..fdf56606 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -81,7 +81,8 @@ ecm_qt_declare_logging_category(SRCS_base ) if(ANDROID) - set (SRCS ${SRCS_base}) + set (SRCS ${SRCS_base} + androidlogging.h) else() set (SRCS ${SRCS_base} mpris2/mediaplayer2.cpp @@ -104,6 +105,7 @@ if(ANDROID) KF5::Kirigami2 Qt::Svg OpenSSL::SSL + log ) kirigami_package_breeze_icons(ICONS diff --git a/src/androidlogging.h b/src/androidlogging.h new file mode 100644 index 00000000..9ab336fb --- /dev/null +++ b/src/androidlogging.h @@ -0,0 +1,36 @@ +/** + * SPDX-FileCopyrightText: 2021 Bart De Vries + * + * SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL + */ + +#pragma once + +#include + +const char *applicationName="org.kde.kasts"; +void myMessageHandler(QtMsgType type, const QMessageLogContext& context, const QString& msg) +{ + QByteArray localMsg = msg.toLocal8Bit(); + // const char *file = context.file ? context.file : ""; + // const char *function = context.function ? context.function : ""; + switch (type) { + case QtDebugMsg: + __android_log_write(ANDROID_LOG_DEBUG,applicationName,localMsg.constData()); + break; + case QtInfoMsg: + __android_log_write(ANDROID_LOG_INFO,applicationName,localMsg.constData()); + break; + case QtWarningMsg: + __android_log_write(ANDROID_LOG_WARN,applicationName,localMsg.constData()); + break; + case QtCriticalMsg: + __android_log_write(ANDROID_LOG_ERROR,applicationName,localMsg.constData()); + break; + case QtFatalMsg: + default: + __android_log_write(ANDROID_LOG_FATAL,applicationName,localMsg.constData()); + abort(); + } +} + diff --git a/src/main.cpp b/src/main.cpp index 4c6bdf69..3f3e938c 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -8,6 +8,7 @@ #include #include #include +#include #include #include #include @@ -26,6 +27,9 @@ #include #include +#ifdef Q_OS_ANDROID +#include "androidlogging.h" +#endif #include "audiomanager.h" #include "database.h" #include "datamanager.h" @@ -48,6 +52,8 @@ int main(int argc, char *argv[]) { #ifdef Q_OS_ANDROID QGuiApplication app(argc, argv); + qInstallMessageHandler(myMessageHandler); + QLoggingCategory::setFilterRules(QStringLiteral("org.kde.*=true")); QQuickStyle::setStyle(QStringLiteral("Material")); #else QApplication app(argc, argv);