13#error "KisAndroidLogHandler can only built on Android platform"
16#include <config-android-stdio-forwarding.h>
17#ifdef ANDROID_ENABLE_STDIO_FORWARDING
19#include <android/log.h>
26const char*
const applicationName=
"krita";
34void kritaQtMessageHandler(QtMsgType type,
const QMessageLogContext& context,
const QString& msg)
37 if (context.file && !QString(context.file).isEmpty()) {
39 report+=QString(context.file);
41 report+=QString::number(context.line);
43 if (context.function && !QString(context.function).isEmpty()) {
44 report+=+
" function ";
45 report+=QString(context.function);
48 const QByteArray local8bit = report.toLocal8Bit();
49 const char *
const local = local8bit.constData();
52 __android_log_write(ANDROID_LOG_DEBUG, applicationName, local);
55 __android_log_write(ANDROID_LOG_INFO, applicationName, local);
58 __android_log_write(ANDROID_LOG_WARN, applicationName, local);
61 __android_log_write(ANDROID_LOG_ERROR, applicationName, local);
65 __android_log_write(ANDROID_LOG_FATAL, applicationName, local);
71static pthread_t loggingThread;
73static void *loggingFunction(
void*) {
77 while((readSize = read(pfd[0], buf,
sizeof buf - 1)) > 0) {
78 if(buf[readSize - 1] ==
'\n') {
84 __android_log_write(ANDROID_LOG_DEBUG, applicationName, buf);
90static int runStdioForwardingThread() {
91 setvbuf(stdout, 0, _IOLBF, 0);
92 setvbuf(stderr, 0, _IONBF, 0);
100 if(pthread_create(&loggingThread, 0, loggingFunction, 0) == -1) {
104 pthread_detach(loggingThread);
113 qInstallMessageHandler(&detail::kritaQtMessageHandler);
114 detail::runStdioForwardingThread();