Skip to content

Commit

Permalink
Improving logging
Browse files Browse the repository at this point in the history
  • Loading branch information
MahBoiDeveloper committed Oct 21, 2024
1 parent f8fddae commit 97d5e22
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 23 deletions.
4 changes: 2 additions & 2 deletions src/GUI/HotkeysMainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ HotkeysMainWindow::HotkeysMainWindow(const QVariant& configuration, QWidget* par
, pAboutDialog{nullptr}
{
SetFactions();
LOGMSG(QString{"Total faction count that has been read from json file: "} + QString::number(factionVector.size()));
LOGMSG(QString("Total faction count that has been read from json file: ") + factionVector.size());

resize(1200, 800);
ConfigureMenu();
Expand Down Expand Up @@ -98,7 +98,7 @@ HotkeysMainWindow::HotkeysMainWindow(const QVariant& configuration, QWidget* par
}
else
{
LOGMSG(QString("Unable to parse more than 12 factions. Found factions : ") + QString::number(factonsCount));
LOGMSG(QString("Unable to parse more than 12 factions. Found factions : ") + factonsCount);
}

connect(pFactionsButtonsGroup, &QButtonGroup::idClicked, this, [=, this](int id)
Expand Down
33 changes: 16 additions & 17 deletions src/Logger.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,29 +68,28 @@ class Logger final
};

template<class T>
concept IsNumber = std::same_as<T, int> || std::same_as<T, size_t>;
concept IsNumber = std::same_as<T, int> || std::same_as<T, size_t> || std::same_as<T, std::size_t>;

template<class T>
concept IsString = std::same_as<T, QString> || std::same_as<T, QChar> ||
std::same_as<T, std::string> || std::same_as<T, std::wstring> ||
std::same_as<T, char> || std::same_as<T, wchar_t> ||
std::same_as<T, const char*> || std::same_as<T, const wchar_t*> ||
std::same_as<T, char*> || std::same_as<T, wchar_t*>;
template<IsNumber N>
QString& operator+ (QString str, N num)
{
return str.append(QString::number(num));
}

template<IsNumber N, IsString S>
QString operator+ (S str, N num)
template<IsNumber N>
QString& operator+ (N num, QString str)
{
return QString(str) + QString::number(num);
return QString::number(num).append(str);
}

template<IsNumber N, IsString S>
QString operator+ (N num, S str)
template<IsNumber N>
QString& operator+ (N num, std::string str)
{
return QString::number(num) + QString(str);
return QString::number(num).append(QString::fromStdString(str));
}

template<IsString S>
QString operator+ (S first, S second)
template<IsNumber N>
QString& operator+ (std::string str, N num)
{
return QString{first} + QString{second};
}
return QString::fromStdString(str).append(QString::number(num));
}
2 changes: 1 addition & 1 deletion src/Parsers/CSFParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ using namespace std;
ReadHeader(&csfFile);
ReadBody(&csfFile);

LOGMSG(string("File \"") + Path + "\" has been parsed; strings count : " + QString::number(qulonglong{Table.size()}).toStdString());
LOGMSG("File \"" + Path + "\" has been parsed; strings count : " + Table.size());
}
else
{
Expand Down
2 changes: 1 addition & 1 deletion src/Parsers/GINIParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ using namespace std;
}
}

LOGMSG( "File \"" + Path + "\" has been parsed; Sections count: " + QString::number(GINIParser::Instance->Sections.size()).toStdString());
LOGMSG( "File \"" + Path + "\" has been parsed; Sections count: " + GINIParser::Instance->Sections.size());
}
else
{
Expand Down
4 changes: 2 additions & 2 deletions src/Parsers/JSONFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ using namespace std;
// Read data from *.json file
if (openedFile.open(QIODevice::ReadOnly | QIODevice::Text))
{
LOGMSG("Parsing \"" + QString{filePath} + "\"...");
LOGMSG("Parsing \"" + filePath + "\"...");
JsonMainObject = QJsonDocument::fromJson(openedFile.readAll(), &err).object();
openedFile.close();
LOGMSG("Errors while parsing: " + err.errorString());
Expand Down Expand Up @@ -118,6 +118,6 @@ using namespace std;
LOGMSG(QString("\tValue is Object? - ") + (val.isObject() ? "True" : "False"));
LOGMSG(QString("\tValue is String? - ") + (val.isString() ? "True" : "False"));
LOGMSG(QString("\tValue is Undefined? - ") + (val.isUndefined() ? "True" : "False"));
LOGMSG(QString("\tLength of array is : " ) + QString::number(val.toArray().size()));
LOGMSG(QString("\tLength of array is : " ) + val.toArray().size());
}
#pragma endregion

0 comments on commit 97d5e22

Please sign in to comment.