From c59a74029b3acde8443db0abebcbc89d78504dee Mon Sep 17 00:00:00 2001 From: Dirk Hohndel Date: Sun, 9 Jul 2017 17:03:57 -0700 Subject: Android: write appLog to file The trick is to pick a path that is accessible from other applications. In theory QStandardPaths::GenericDataLocation should provide that. Signed-off-by: Dirk Hohndel --- qt-models/messagehandlermodel.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'qt-models') diff --git a/qt-models/messagehandlermodel.cpp b/qt-models/messagehandlermodel.cpp index ec6e818c9..d783a3da6 100644 --- a/qt-models/messagehandlermodel.cpp +++ b/qt-models/messagehandlermodel.cpp @@ -2,11 +2,12 @@ #include "messagehandlermodel.h" /* based on logging bits from libdivecomputer */ -#ifndef __ANDROID__ +#if !defined(Q_OS_ANDROID) #define INFO(fmt, ...) fprintf(stderr, "INFO: " fmt "\n", ##__VA_ARGS__) #else +extern void writeToAppLogFile(QString logText); #include -#define INFO(fmt, ...) __android_log_print(ANDROID_LOG_DEBUG, __FILE__, "INFO: " fmt "\n", ##__VA_ARGS__) +#define INFO(fmt, ...) __android_log_print(ANDROID_LOG_DEBUG, __FILE__, "INFO: " fmt "\n", ##__VA_ARGS__); #endif void logMessageHandler(QtMsgType type, const QMessageLogContext &context, const QString &msg) @@ -42,6 +43,9 @@ void MessageHandlerModel::addLog(QtMsgType type, const QString& message) m_data.append({message, type}); endInsertRows(); INFO("%s", message.toUtf8().constData()); +#if defined (Q_OS_ANDROID) + writeToAppLogFile(message); +#endif } QVariant MessageHandlerModel::data(const QModelIndex& idx, int role) const -- cgit v1.2.3-70-g09d2