Commit c255a9ad authored by Laurent Montel's avatar Laurent Montel 😁
Browse files

use QLoggingCategory for logging

Summary:
Logging with QLoggingCategory instead of QtGlobal functions (qDebug, qInfo, etc)
allow users to filter out unwanted messages with kdebugsettings and qtlogging.ini

Reviewers: mlaurent

Reviewed By: mlaurent

Subscribers: mlaurent, kde-pim

Tags: #kde_pim

Differential Revision: https://phabricator.kde.org/D26246
parent 12005abf
......@@ -19,7 +19,7 @@ include(ECMGeneratePriFile)
include(ECMGenerateHeaders)
include(ECMSetupVersion)
include(FeatureSummary)
include(ECMQtDeclareLoggingCategory)
set(KMIME_LIB_VERSION ${PIM_VERSION})
......@@ -78,4 +78,9 @@ install(FILES
COMPONENT Devel
)
install(FILES
kmime.categories
DESTINATION ${KDE_INSTALL_LOGGINGCATEGORIESDIR}
)
feature_summary(WHAT ALL FATAL_ON_MISSING_REQUIRED_PACKAGES)
org.kde.pim.kmime kmime (pim lib) IDENTIFIER [KMIME_LOG]
......@@ -24,6 +24,12 @@ set(kmime_LIB_SRCS
kmime_types.cpp
)
ecm_qt_declare_logging_category(kmime_LIB_SRCS
HEADER kmime_debug.h
IDENTIFIER KMIME_LOG
CATEGORY_NAME org.kde.pim.kmime
)
add_library(KF5Mime ${kmime_LIB_SRCS})
generate_export_header(KF5Mime BASE_NAME KMime)
......
......@@ -32,6 +32,7 @@
*/
#include "kmime_charfreq.h"
#include "kmime_debug.h"
using namespace KMime;
......@@ -194,7 +195,7 @@ bool CharFreq::hasLeadingFrom() const
CharFreq::Type CharFreq::type() const
{
#if 0
qDebug("Total: %d; NUL: %d; CTL: %d;\n"
qCDebug(KMIME_LOG)("Total: %d; NUL: %d; CTL: %d;\n"
"CR: %d; LF: %d; CRLF: %d;\n"
"lineMin: %d; lineMax: %d;\n"
"printable: %d; eightBit: %d;\n"
......
......@@ -46,7 +46,6 @@
#include <KCodecs/KCodecs>
#include <KLocalizedString>
#include <QDebug>
#include <QTextCodec>
#include <QByteArray>
......
......@@ -28,6 +28,7 @@
#include "kmime_util_p.h"
#include "kmime_codecs.h"
#include "kmime_dateformatter.h"
#include "kmime_debug.h"
#include "kmime_warning.h"
#include <KCharsets>
......@@ -68,7 +69,7 @@ bool parseEncodedWord(const char *&scursor, const char *const send,
char ch = *scursor++;
if (ch != '?') {
// qDebug() << "first";
// qCDebug(KMIME_LOG) << "first";
//KMIME_WARN_PREMATURE_END_OF( EncodedWord );
return false;
}
......@@ -90,7 +91,7 @@ bool parseEncodedWord(const char *&scursor, const char *const send,
// not found? can't be an encoded-word!
if (scursor == send || *scursor != '?') {
// qDebug() << "second";
// qCDebug(KMIME_LOG) << "second";
KMIME_WARN_PREMATURE_END_OF(EncodedWord);
return false;
}
......@@ -121,7 +122,7 @@ bool parseEncodedWord(const char *&scursor, const char *const send,
// not found? Can't be an encoded-word!
if (scursor == send || *scursor != '?') {
// qDebug() << "third";
// qCDebug(KMIME_LOG) << "third";
KMIME_WARN_PREMATURE_END_OF(EncodedWord);
return false;
}
......@@ -129,7 +130,7 @@ bool parseEncodedWord(const char *&scursor, const char *const send,
// extract the encoding information:
QByteArray maybeEncoding(encodingStart, scursor - encodingStart);
// qDebug() << "parseEncodedWord: found charset == \"" << maybeCharset
// qCDebug(KMIME_LOG) << "parseEncodedWord: found charset == \"" << maybeCharset
// << "\"; language == \"" << maybeLanguage
// << "\"; encoding == \"" << maybeEncoding << "\"";
......@@ -207,7 +208,7 @@ bool parseEncodedWord(const char *&scursor, const char *const send,
return false;
};
// qDebug() << "mimeName(): \"" << textCodec->name() << "\"";
// qCDebug(KMIME_LOG) << "mimeName(): \"" << textCodec->name() << "\"";
// allocate a temporary buffer to store the 8bit text:
int encodedTextLength = encodedTextEnd - encodedTextStart;
......@@ -228,7 +229,7 @@ bool parseEncodedWord(const char *&scursor, const char *const send,
result = textCodec->toUnicode(buffer.data(), bbegin - buffer.data());
// qDebug() << "result now: \"" << result << "\"";
// qCDebug(KMIME_LOG) << "result now: \"" << result << "\"";
// cleanup:
delete dec;
language = maybeLanguage;
......@@ -1452,7 +1453,7 @@ static void decodeRFC2231Value(KCodecs::Codec *&rfc2231Codec,
value += textcodec->toUnicode(buffer.begin(), bit - buffer.begin());
// qDebug() << "value now: \"" << value << "\"";
// qCDebug(KMIME_LOG) << "value now: \"" << value << "\"";
// cleanup:
delete dec;
}
......@@ -1611,7 +1612,7 @@ static bool parseDayName(const char *&scursor, const char *const send)
for (int i = 0 ; i < stdDayNamesLen ; ++i) {
if (qstrnicmp(scursor, stdDayNames[i], 3) == 0) {
scursor += 3;
// qDebug() << "found" << stdDayNames[i];
// qCDebug(KMIME_LOG) << "found" << stdDayNames[i];
return true;
}
}
......@@ -2049,7 +2050,7 @@ Headers::Base *extractHeader(const QByteArray &head, const int headerStart, int
header = HeaderFactory::createHeader(rawType, rawTypeLen);
}
if (!header) {
//qWarning() << "Returning Generic header of type" << rawType;
//qCWarning(KMIME_LOG)() << "Returning Generic header of type" << rawType;
header = new Headers::Generic(rawType, rawTypeLen);
}
if (folded) {
......
......@@ -46,9 +46,9 @@
#include "kmime_content.h"
#include "kmime_header_parsing.h"
#include "kmime_headerfactory_p.h"
#include "kmime_debug.h"
#include "kmime_warning.h"
#include <KCharsets>
#include <KCodecs>
......@@ -293,7 +293,7 @@ static bool stringToMailbox(const QByteArray &address,
const char *cursor = address.constData();
if (!parseAngleAddr(cursor, cursor + address.length(), addrSpec)) {
if (!parseAddrSpec(cursor, cursor + address.length(), addrSpec)) {
qWarning() << "stringToMailbox: Invalid address";
qCWarning(KMIME_LOG) << "stringToMailbox: Invalid address";
return false;
}
}
......@@ -848,7 +848,7 @@ QByteArray Parametrized::as7BitString(bool withHeaderType) const
} else {
if (useOutlookAttachmentEncoding()) {
rv += it.key().toLatin1() + '=';
qDebug() << "doing:" << it.value() << QLatin1String(d->encCS);
qCDebug(KMIME_LOG) << "doing:" << it.value() << QLatin1String(d->encCS);
rv += "\"" + encodeRFC2047String(it.value(), d->encCS) + "\"";
} else {
rv += it.key().toLatin1() + "*=";
......@@ -1028,7 +1028,7 @@ void Ident::appendIdentifier(const QByteArray &id)
if (parseAngleAddr(cursor, cursor + tmp.length(), msgId)) {
d->msgIdList.append(msgId);
} else {
qWarning() << "Unable to parse address spec!";
qCWarning(KMIME_LOG) << "Unable to parse address spec!";
}
}
......
......@@ -35,9 +35,9 @@
#include "kmime_version.h"
#include "kmime_util.h"
#include "kmime_codecs.h"
#include "kmime_debug.h"
#include <KLocalizedString>
#include <QDebug>
#include <QByteArray>
......@@ -297,7 +297,7 @@ QString descriptionFor(DispositionType d,
return i18n(dispositionTypes[i].description);
}
}
qWarning() << "KMime::MDN::descriptionFor(): No such disposition type:"
qCWarning(KMIME_LOG) << "KMime::MDN::descriptionFor(): No such disposition type:"
<< static_cast<int>(d);
return QString();
}
......
......@@ -26,10 +26,10 @@
#include "kmime_header_parsing_p.h"
#include "kmime_util.h"
#include "kmime_util_p.h"
#include "kmime_debug.h"
#include <KCodecs>
#include <QDebug>
#include <QStringList>
#include <QUrl>
......@@ -136,7 +136,7 @@ void Mailbox::setAddress(const QByteArray &addr)
cursor + addr.length(), mAddrSpec)) {
if (!HeaderParsing::parseAddrSpec(cursor, cursor + addr.length(),
mAddrSpec)) {
qWarning() << "Mailbox: Invalid address";
qCWarning(KMIME_LOG) << "Mailbox: Invalid address";
return;
}
}
......
......@@ -25,6 +25,7 @@
#include "kmime_util_p.h"
#include "kmime_charfreq.h"
#include "kmime_debug.h"
#include "kmime_header_parsing.h"
#include "kmime_message.h"
#include "kmime_warning.h"
......@@ -34,7 +35,6 @@
#include <KLocalizedString>
#include <KCharsets>
#include <QDebug>
#include <QCoreApplication>
#include <QVector>
......@@ -62,7 +62,7 @@ QByteArray cachedCharset(const QByteArray &name)
}
c_harsetCache.append(name.toUpper());
//qDebug() << "KNMimeBase::cachedCharset() number of cs" << c_harsetCache.count();
//qCDebug(KMIME_LOG) << "KNMimeBase::cachedCharset() number of cs" << c_harsetCache.count();
return c_harsetCache.last();
}
......@@ -166,7 +166,7 @@ QByteArray uniqueString()
for (int i = 0; i < 10; i++) {
int pos = (int)(61.0 * rand() / (RAND_MAX + 1.0));
//qDebug() << pos;
//qCDebug(KMIME_LOG) << pos;
p[i] = chars[pos];
}
......@@ -492,7 +492,7 @@ KMIME_EXPORT QString balanceBidiState(const QString &input)
openDirChangers--;
} else {
// One PDF too much, remove it
qWarning() << "Possible Unicode spoofing (unexpected PDF) detected in" << input;
qCWarning(KMIME_LOG) << "Possible Unicode spoofing (unexpected PDF) detected in" << input;
result.remove(i - numPDFsRemoved, 1);
numPDFsRemoved++;
}
......@@ -500,7 +500,7 @@ KMIME_EXPORT QString balanceBidiState(const QString &input)
}
if (openDirChangers > 0) {
qWarning() << "Possible Unicode spoofing detected in" << input;
qCWarning(KMIME_LOG) << "Possible Unicode spoofing detected in" << input;
// At PDF chars to the end until the correct state is restored.
// As a special exception, when encountering quoted strings, place the PDF before
......
......@@ -25,8 +25,8 @@
#define KMIME_WARNING_H
#ifndef KMIME_NO_WARNING
# include <qdebug.h>
# define KMIME_WARN qDebug() << "Tokenizer Warning:"
# include "kmime_debug.h"
# define KMIME_WARN qCDebug(KMIME_LOG) << "Tokenizer Warning:"
# define KMIME_WARN_UNKNOWN(x,y) KMIME_WARN << "unknown " #x ": \"" \
<< y << "\"";
# define KMIME_WARN_UNKNOWN_ENCODING KMIME_WARN << "unknown encoding in " \
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment