debug::Log can now be used instead of qDebug()

Usage:
```
QString string("world");
debug::Log("hello: {}", string);
```
This commit is contained in:
Rasmus Karlsson 2017-09-24 19:23:07 +02:00
parent af35c1f335
commit 81e06f3a53
3 changed files with 50 additions and 8 deletions

View file

@ -164,7 +164,8 @@ HEADERS += \
src/widgets/qualitypopup.hpp \
src/widgets/emotepopup.hpp \
src/messages/messagecolor.hpp \
src/util/nativeeventhelper.hpp
src/util/nativeeventhelper.hpp \
src/debug/log.hpp
PRECOMPILED_HEADER =
@ -178,6 +179,11 @@ win32 {
INCLUDEPATH += C:\local\boost\
}
win32 {
LIBS += -luser32
LIBS += -lgdi32
}
# Optional dependency on windows sdk 7.1
win32:exists(C:\Program Files\Microsoft SDKs\Windows\v7.1\Include\Windows.h) {
LIBS += -L"C:\Program Files\Microsoft SDKs\Windows\v7.1\Lib" \

37
src/debug/log.hpp Normal file
View file

@ -0,0 +1,37 @@
#pragma once
#include "fmt/format.h"
#include <QDebug>
#include <QTime>
namespace chatterino {
namespace debug {
namespace detail {
static void _log(const std::string &message)
{
qDebug().noquote() << QTime::currentTime().toString("hh:mm:ss.zzz") << message.c_str();
}
} // namespace detail
template <typename... Args>
inline void Log(const std::string &formatString, Args &&... args)
{
detail::_log(fmt::format(formatString, std::forward<Args>(args)...));
}
} // namespace debug
} // namespace chatterino
namespace fmt {
// format_arg for QString
inline void format_arg(BasicFormatter<char> &f, const char *&, const QString &v)
{
f.writer().write("\"{}\"", v.toStdString());
}
} // namespace fmt

View file

@ -1,5 +1,6 @@
#include "twitch/twitchmessagebuilder.hpp"
#include "colorscheme.hpp"
#include "debug/log.hpp"
#include "emotemanager.hpp"
#include "ircmanager.hpp"
#include "resources.hpp"
@ -414,8 +415,8 @@ void TwitchMessageBuilder::parseHighlights()
if (!blackList.contains(this->ircMessage->nick(), Qt::CaseInsensitive)) {
for (const Highlight &highlight : activeHighlights) {
if (this->originalMessage.contains(highlight.target, Qt::CaseInsensitive)) {
qDebug() << "Highlight because " << this->originalMessage << " contains "
<< highlight.target;
debug::Log("Highlight because {} contains {}", this->originalMessage,
highlight.target);
doHighlight = true;
if (highlight.sound) {
@ -569,13 +570,11 @@ void TwitchMessageBuilder::parseTwitchBadges()
Word(badgeVersion.badgeImage1x, Word::BadgeVanity, QString(),
QString("Twitch " + QString::fromStdString(badgeVersion.title))));
} catch (const std::exception &e) {
qDebug() << "Exception caught:" << e.what()
<< "when trying to fetch badge version " << versionKey.c_str();
debug::Log("Exception caught: {} when trying to fetch badge version {}",
e.what(), versionKey);
}
} catch (const std::exception &e) {
qDebug() << "No badge set with key"
<< "bits"
<< ". Exception: " << e.what();
debug::Log("No badge set with key bits. Exception: {}", e.what());
}
} else if (badge == "staff/1") {
appendWord(Word(this->resources.badgeStaff, Word::BadgeGlobalAuthority, QString(),