File indexing completed on 2022-09-27 16:31:47

0001 /*
0002     SPDX-FileCopyrightText: 2016-2022 Laurent Montel <montel@kde.org>
0003 
0004     SPDX-License-Identifier: LGPL-2.0-or-later
0005 
0006 */
0007 
0008 #include "loggingcategory.h"
0009 
0010 LoggingCategory::LoggingCategory() = default;
0011 
0012 bool LoggingCategory::operator==(const LoggingCategory &other) const
0013 {
0014     return (description == other.description) && (categoryName == other.categoryName) && (enabled == other.enabled) && (loggingType == other.loggingType)
0015         && (defaultSeverityType == other.defaultSeverityType) && (identifierName == other.identifierName);
0016 }
0017 
0018 bool LoggingCategory::isValid() const
0019 {
0020     return !categoryName.isEmpty() && (loggingType != Undefined);
0021 }
0022 
0023 QString LoggingCategory::createCustomRule() const
0024 {
0025     QString str;
0026     switch (loggingType) {
0027     case All:
0028         str = categoryName + (enabled ? QStringLiteral("=true\n") : QStringLiteral("=false\n"));
0029         break;
0030     case Info:
0031         str = categoryName + QStringLiteral(".info=%1\n").arg(enabled ? QStringLiteral("true") : QStringLiteral("false"));
0032         break;
0033     case Warning:
0034         str = categoryName + QStringLiteral(".warning=%1\n").arg(enabled ? QStringLiteral("true") : QStringLiteral("false"));
0035         break;
0036     case Debug:
0037         str = categoryName + QStringLiteral(".debug=%1\n").arg(enabled ? QStringLiteral("true") : QStringLiteral("false"));
0038         break;
0039     case Critical:
0040         str = categoryName + QStringLiteral(".critical=%1\n").arg(enabled ? QStringLiteral("true") : QStringLiteral("false"));
0041         break;
0042     case Undefined:
0043     case Off:
0044         str = QString();
0045         break;
0046     }
0047     return str;
0048 }
0049 
0050 QString LoggingCategory::createRule() const
0051 {
0052     QString str;
0053     switch (loggingType) {
0054     case Undefined:
0055         break;
0056     case All:
0057         str = categoryName + QLatin1String("=true\n");
0058         break;
0059     case Info:
0060         str = categoryName + QLatin1String(".info=true\n");
0061         str += categoryName + QLatin1String(".warning=true\n");
0062         str += categoryName + QLatin1String(".critical=true\n");
0063         str += categoryName + QLatin1String(".debug=false\n");
0064         break;
0065     case Warning:
0066         str = categoryName + QLatin1String(".info=false\n");
0067         str += categoryName + QLatin1String(".debug=false\n");
0068         str += categoryName + QLatin1String(".warning=true\n");
0069         str += categoryName + QLatin1String(".critical=true\n");
0070         break;
0071     case Debug:
0072         str = categoryName + QLatin1String(".info=false\n");
0073         str += categoryName + QLatin1String(".debug=true\n");
0074         str += categoryName + QLatin1String(".warning=true\n");
0075         str += categoryName + QLatin1String(".critical=true\n");
0076         break;
0077     case Critical:
0078         str = categoryName + QLatin1String(".info=false\n");
0079         str += categoryName + QLatin1String(".debug=false\n");
0080         str += categoryName + QLatin1String(".warning=false\n");
0081         str += categoryName + QLatin1String(".critical=true\n");
0082         break;
0083     case Off:
0084         str = categoryName + QLatin1String(".info=false\n");
0085         str += categoryName + QLatin1String(".debug=false\n");
0086         str += categoryName + QLatin1String(".warning=false\n");
0087         str += categoryName + QLatin1String(".critical=false\n");
0088         break;
0089     }
0090     return str;
0091 }
0092 
0093 QDebug operator<<(QDebug d, const LoggingCategory &cat)
0094 {
0095     d << "customcategories cat: " << cat.description;
0096     d << "logname: " << cat.categoryName;
0097     d << "enabled: " << cat.enabled;
0098     d << "type: " << cat.loggingType;
0099     d << "identifier: " << cat.identifierName;
0100     d << "default category: " << cat.defaultSeverityType;
0101     return d;
0102 }