File indexing completed on 2024-05-05 14:22:14
0001 // SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL 0002 // SPDX-FileCopyrightText: 2020 Harald Sitter <sitter@kde.org> 0003 0004 #include "Logger.h" 0005 0006 #include "Debug.h" 0007 0008 Logger *Logger::instance() 0009 { 0010 static Logger logger; 0011 return &logger; 0012 } 0013 0014 void Logger::install() 0015 { 0016 previousHandler = qInstallMessageHandler(&Logger::handler); 0017 } 0018 0019 Q_INVOKABLE QStringList Logger::log() 0020 { 0021 return data; 0022 } 0023 0024 void Logger::handler(QtMsgType type, const QMessageLogContext &context, const QString &msg) 0025 { 0026 // Record our category and the default (default is not categorized output) 0027 // But skip over random qDebugs on qml files. We aren't producing debug output from qml that is worth logging. 0028 if ((strcmp(context.category, INSTALLER().categoryName()) == 0 || strcmp(context.category, "default") == 0) && 0029 !msg.contains(QLatin1String(".qml"))) { 0030 instance()->data << QStringLiteral("[%1] %2\n").arg(QString::fromLatin1(context.function), msg); 0031 } 0032 // Forward all calls to the default handler. 0033 if (auto previous = instance()->previousHandler; previous) { 0034 previous(type, context, msg); 0035 } 0036 }