Add basic logging capabilities on android.

This implements debug logging which can be checked through logcat.
This commit is contained in:
Bart De Vries 2021-06-19 00:12:35 +02:00
parent 60432619f1
commit 4d6d8ae940
3 changed files with 45 additions and 1 deletions

View File

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

36
src/androidlogging.h Normal file
View File

@ -0,0 +1,36 @@
/**
* SPDX-FileCopyrightText: 2021 Bart De Vries <bart@mogwai.be>
*
* SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
*/
#pragma once
#include <android/log.h>
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();
}
}

View File

@ -8,6 +8,7 @@
#include <QCommandLineOption>
#include <QCommandLineParser>
#include <QIcon>
#include <QLoggingCategory>
#include <QQmlApplicationEngine>
#include <QQmlContext>
#include <QQuickStyle>
@ -26,6 +27,9 @@
#include <KLocalizedContext>
#include <KLocalizedString>
#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);