Skip to content

Commit

Permalink
Refactored all logging code
Browse files Browse the repository at this point in the history
time to remove all printfs and Utils::Formats :')
  • Loading branch information
WorkingRobot committed Jun 5, 2021
1 parent 359da37 commit b76563f
Show file tree
Hide file tree
Showing 43 changed files with 480 additions and 344 deletions.
9 changes: 6 additions & 3 deletions src/main.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "modules/ModuleList.h"
#include "modules/Login/Auth.h"
#include "utils/Assert.h"
#include "utils/Log.h"
#include "utils/Config.h"
#include "utils/FontSetup.h"
#include "utils/Format.h"
Expand All @@ -12,7 +12,7 @@ namespace EGL3 {
MainApp() :
App(Gtk::Application::create("me.workingrobot.egl3", Gio::ApplicationFlags::APPLICATION_HANDLES_COMMAND_LINE))
{
EGL3_LOG(LogLevel::Info, Utils::Format("Starting up %s/%s %s/%s", Utils::Config::GetAppName(), Utils::Config::GetAppVersion(), Utils::Platform::GetOSName(), Utils::Platform::GetOSVersion().c_str()).c_str());
EGL3_LOGF(LogLevel::Info, "Starting up {}/{} {}/{}", Utils::Config::GetAppName(), Utils::Config::GetAppVersion(), Utils::Platform::GetOSName(), Utils::Platform::GetOSVersion());

App->signal_command_line().connect(sigc::mem_fun(this, &MainApp::OnCommandLine), false);
App->signal_startup().connect(sigc::mem_fun(this, &MainApp::OnStartup));
Expand Down Expand Up @@ -40,7 +40,7 @@ namespace EGL3 {
{
auto StyleData = Gtk::CssProvider::create();
StyleData->signal_parsing_error().connect([&](const Glib::RefPtr<const Gtk::CssSection>& Section, const Glib::Error& Error) {
EGL3_LOG(LogLevel::Critical, "Failed to parse style data properly");
EGL3_ABORTF("Failed to parse style data properly ({}) at {} @ {}", (std::string)Error.what(), Section->get_file()->get_path(), Section->get_start_line() + 1);
});
StyleData->load_from_path("resources\\EGL3.css");
Gtk::StyleContext::add_provider_for_screen(Gdk::Screen::get_default(), StyleData, GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
Expand Down Expand Up @@ -82,6 +82,9 @@ namespace EGL3 {

#ifdef USE_SUBSYSTEM_CONSOLE

#include "utils/Log.h"
#include <iostream>

int main(int argc, char* argv[]) {
return EGL3::Start();
}
Expand Down
2 changes: 1 addition & 1 deletion src/modules/Friends/Chat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ namespace EGL3::Modules::Friends {

void ChatModule::SetUser(const Friend& Friend)
{
if (!EGL3_CONDITIONAL_LOG(!SelectedFriend, LogLevel::Warning, "Trying to set selected friend before clearing. Clearing now.")) {
if (!EGL3_ENSURE(!SelectedFriend, LogLevel::Warning, "Trying to set selected friend before clearing. Clearing now.")) {
ClearUser();
}

Expand Down
4 changes: 2 additions & 2 deletions src/modules/Friends/Friends.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ namespace EGL3::Modules::Friends {
FriendsList.FriendMenuAction.Set([this](auto Action, const auto& Friend) { OnFriendAction(Action, Friend); });

FriendsChat.SendChatMessage.Set([this](const auto& AccountId, const auto& Content) {
if (EGL3_CONDITIONAL_LOG(XmppClient.has_value(), LogLevel::Critical, "Didn't send user message. Xmpp client isn't created yet")) {
if (EGL3_VERIFY(XmppClient.has_value(), "Didn't send user message. Xmpp client isn't created yet")) {
XmppClient->SendChat(AccountId, Content);
}
});
Expand All @@ -81,7 +81,7 @@ namespace EGL3::Modules::Friends {

{
auto& AuthData = Auth.GetClientLauncher().GetAuthData();
EGL3_CONDITIONAL_LOG(AuthData.AccountId.has_value(), LogLevel::Critical, "Launcher client does not have an attached account id");
EGL3_VERIFY(AuthData.AccountId.has_value(), "Launcher client does not have an attached account id");

FriendsList.GetCurrentUser().SetCurrentUserData(AuthData.AccountId.value(), AuthData.DisplayName.value());

Expand Down
4 changes: 2 additions & 2 deletions src/modules/Friends/List.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ namespace EGL3::Modules::Friends {
auto APtr = (Widgets::FriendItem*)A->get_child()->get_data("EGL3_FriendBase");
auto BPtr = (Widgets::FriendItem*)B->get_child()->get_data("EGL3_FriendBase");

EGL3_CONDITIONAL_LOG(APtr && BPtr, LogLevel::Critical, "Widgets aren't of type FriendItem");
EGL3_VERIFY(APtr && BPtr, "Widgets aren't of type FriendItem");

std::weak_ordering Comp;

Expand All @@ -46,7 +46,7 @@ namespace EGL3::Modules::Friends {
List.set_filter_func([this](Gtk::ListBoxRow* Row) {
auto Ptr = (Widgets::FriendItem*)Row->get_child()->get_data("EGL3_FriendBase");

EGL3_CONDITIONAL_LOG(Ptr, LogLevel::Critical, "Widget isn't of type FriendItem");
EGL3_VERIFY(Ptr, "Widget isn't of type FriendItem");

if (FilterEntry.get_text_length()) {
std::string Text = FilterEntry.get_text();
Expand Down
2 changes: 1 addition & 1 deletion src/modules/Game/Download.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ namespace EGL3::Modules::Game {
});

auto VersionData = GameInfo.GetVersionData(Id);
EGL3_CONDITIONAL_LOG(VersionData, LogLevel::Critical, "Version data should be valid at this point");
EGL3_VERIFY(VersionData, "Version data should be valid at this point");
auto InstallOpts = GameInfo.GetInstallOptions(Id, VersionData->Element.BuildVersion);

auto& Data = CurrentDownload->GetStateData<DownloadInfo::StateOptions>();
Expand Down
4 changes: 2 additions & 2 deletions src/modules/Game/Game.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "Game.h"

#include "../../storage/game/Archive.h"
#include "../../utils/Assert.h"
#include "../../utils/Log.h"
#include "../../web/epic/EpicClient.h"

#include <charconv>
Expand Down Expand Up @@ -68,7 +68,7 @@ namespace EGL3::Modules::Game {

PlayStateHolder.Clicked.Set([this]() {
auto Install = GetInstall(PrimaryGame);
EGL3_CONDITIONAL_LOG(Install, LogLevel::Critical, "No game, but playable?");
EGL3_VERIFY(Install, "No game, but playable?");
Play.OnPlayClicked(*Install);

PlayStateHolder.SetHeldState(State::Playing);
Expand Down
4 changes: 2 additions & 2 deletions src/modules/Game/Service.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "Service.h"

#include "../../utils/Assert.h"
#include "../../utils/Log.h"
#include "../../utils/Config.h"
#include "../../utils/Format.h"

Expand All @@ -26,7 +26,7 @@ namespace EGL3::Modules::Game {
Client.Connect(ClientName);
}
}
EGL3_CONDITIONAL_LOG(Client.IsConnected(), LogLevel::Critical, "Could not connect to the service after multiple retries");
EGL3_VERIFY(Client.IsConnected(), "Could not connect to the service after multiple retries");
}

Service::Pipe::Client& ServiceModule::GetClient()
Expand Down
22 changes: 11 additions & 11 deletions src/modules/Login/Auth.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ namespace EGL3::Modules::Login {
void AuthModule::OpenSignInPage()
{
auto Result = InstallSignInProtocol();
if (EGL3_CONDITIONAL_LOG(Result == ERROR_SUCCESS, LogLevel::Error, "Could not set intent protocol in registry")) {
if (EGL3_ENSURE(Result == ERROR_SUCCESS, LogLevel::Error, "Could not set intent protocol in registry")) {
Utils::OpenInBrowser("https://www.epicgames.com/id/login?client_id=3f69e56c7649492c8cc29f1af08a8a12&response_type=code&display=popup&prompt=login");
}
else {
Expand Down Expand Up @@ -210,14 +210,14 @@ namespace EGL3::Modules::Login {

SignInTask = std::async(std::launch::async, [this, AuthCodeString = AuthCode]() {
Web::Epic::Auth::AuthorizationCode AuthCode(Web::AuthClientAndroid, AuthCodeString);
if (!EGL3_CONDITIONAL_LOG(AuthCode.GetOAuthResponseFuture().get() == Web::Epic::Auth::AuthorizationCode::SUCCESS, LogLevel::Error, "Could not use auth code")) {
if (!EGL3_ENSURE(AuthCode.GetOAuthResponseFuture().get() == Web::Epic::Auth::AuthorizationCode::SUCCESS, LogLevel::Error, "Could not use auth code")) {
return;
}
Web::Epic::EpicClientAuthed AuthCodeClient(AuthCode.GetOAuthResponse(), Web::AuthClientAndroid);

auto& AuthData = AuthCodeClient.GetAuthData();
auto KairosDataResp = AuthCodeClient.GetSettingsForAccounts({ AuthData.AccountId.value() }, { "avatar", "avatarBackground" });
if (!EGL3_CONDITIONAL_LOG(!KairosDataResp.HasError(), LogLevel::Error, "Could not get kairos data from android client")) {
if (!EGL3_ENSURE(!KairosDataResp.HasError(), LogLevel::Error, "Could not get kairos data from android client")) {
return;
}

Expand All @@ -241,21 +241,21 @@ namespace EGL3::Modules::Login {
SignInDispatcher.emit();

auto FortniteCodeResp = AuthCodeClient.GetExchangeCode();
if (!EGL3_CONDITIONAL_LOG(!FortniteCodeResp.HasError(), LogLevel::Error, "Could not get exchange code from android client #1")) {
if (!EGL3_ENSURE(!FortniteCodeResp.HasError(), LogLevel::Error, "Could not get exchange code from android client #1")) {
return;
}
auto LauncherCodeResp = AuthCodeClient.GetExchangeCode();
if (!EGL3_CONDITIONAL_LOG(!LauncherCodeResp.HasError(), LogLevel::Error, "Could not get exchange code from android client #2")) {
if (!EGL3_ENSURE(!LauncherCodeResp.HasError(), LogLevel::Error, "Could not get exchange code from android client #2")) {
return;
}

Web::Epic::Auth::ExchangeCode FortniteAuth(Web::AuthClientPC, FortniteCodeResp->Code);
if (!EGL3_CONDITIONAL_LOG(FortniteAuth.GetOAuthResponseFuture().get() == Web::Epic::Auth::ExchangeCode::SUCCESS, LogLevel::Error, "Could not use exchange code for fortnite")) {
if (!EGL3_ENSURE(FortniteAuth.GetOAuthResponseFuture().get() == Web::Epic::Auth::ExchangeCode::SUCCESS, LogLevel::Error, "Could not use exchange code for fortnite")) {
return;
}

Web::Epic::Auth::ExchangeCode LauncherAuth(Web::AuthClientLauncher, LauncherCodeResp->Code);
if (!EGL3_CONDITIONAL_LOG(LauncherAuth.GetOAuthResponseFuture().get() == Web::Epic::Auth::ExchangeCode::SUCCESS, LogLevel::Error, "Could not use exchange code for launcher")) {
if (!EGL3_ENSURE(LauncherAuth.GetOAuthResponseFuture().get() == Web::Epic::Auth::ExchangeCode::SUCCESS, LogLevel::Error, "Could not use exchange code for launcher")) {
return;
}

Expand All @@ -273,18 +273,18 @@ namespace EGL3::Modules::Login {
SignInDispatcher.emit();

Web::Epic::Auth::RefreshToken LauncherAuth(Web::AuthClientLauncher, Data.RefreshToken);
if (!EGL3_CONDITIONAL_LOG(LauncherAuth.GetOAuthResponseFuture().get() == Web::Epic::Auth::RefreshToken::SUCCESS, LogLevel::Error, "Could not use refresh token")) {
if (!EGL3_ENSURE(LauncherAuth.GetOAuthResponseFuture().get() == Web::Epic::Auth::RefreshToken::SUCCESS, LogLevel::Error, "Could not use refresh token")) {
return;
}
Web::Epic::EpicClientAuthed LauncherClient(LauncherAuth.GetOAuthResponse(), Web::AuthClientLauncher);

auto FortniteCodeResp = LauncherClient.GetExchangeCode();
if (!EGL3_CONDITIONAL_LOG(!FortniteCodeResp.HasError(), LogLevel::Error, "Could not get exchange code from launcher client")) {
if (!EGL3_ENSURE(!FortniteCodeResp.HasError(), LogLevel::Error, "Could not get exchange code from launcher client")) {
return;
}

Web::Epic::Auth::ExchangeCode FortniteAuth(Web::AuthClientPC, FortniteCodeResp->Code);
if (!EGL3_CONDITIONAL_LOG(FortniteAuth.GetOAuthResponseFuture().get() == Web::Epic::Auth::ExchangeCode::SUCCESS, LogLevel::Error, "Could not use exchange code for fortnite")) {
if (!EGL3_ENSURE(FortniteAuth.GetOAuthResponseFuture().get() == Web::Epic::Auth::ExchangeCode::SUCCESS, LogLevel::Error, "Could not use exchange code for fortnite")) {
return;
}

Expand Down Expand Up @@ -323,7 +323,7 @@ namespace EGL3::Modules::Login {
.RefreshExpireTime = AuthData.RefreshExpiresAt.value()
};
auto KairosDataResp = Fortnite.GetSettingsForAccounts({ AuthData.AccountId.value() }, { "avatar", "avatarBackground" });
if (EGL3_CONDITIONAL_LOG(!KairosDataResp.HasError(), LogLevel::Error, "Could not get kairos data from fortnite client on launcher refresh")) {
if (EGL3_ENSURE(!KairosDataResp.HasError(), LogLevel::Error, "Could not get kairos data from fortnite client on launcher refresh")) {
for (auto& Setting : KairosDataResp->Values) {
if (Setting.AccountId != AuthData.AccountId.value()) {
continue;
Expand Down
5 changes: 1 addition & 4 deletions src/modules/ModuleList.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
#include "ModuleList.h"

#include "../utils/type_name.h"

#include "AsyncFF.h"
#include "ImageCache.h"
#include "StatsGraph.h"
Expand Down Expand Up @@ -102,7 +100,6 @@ namespace EGL3::Modules {
template<typename T>
void ModuleList::AddModule() {
Modules.emplace_back(std::make_unique<T>(*this));
static constexpr std::string_view Name = type_name_v<T>.substr(sizeof("class EGL3::Modules::") - 1);
EGL3_LOG(LogLevel::Info, Utils::Format("%.*s loaded", Name.size(), Name.data()).c_str());
EGL3_LOGF(LogLevel::Info, "{} loaded", Detail::module_name_v<T>);
}
}
12 changes: 9 additions & 3 deletions src/modules/ModuleList.h
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
#pragma once

#include "../storage/persistent/Store.h"
#include "../utils/Assert.h"
#include "../utils/GladeBuilder.h"
#include "../utils/Log.h"
#include "../utils/type_name.h"
#include "BaseModule.h"

namespace EGL3::Modules {
namespace Detail {
template<typename T, std::enable_if_t<type_name_v<T>.starts_with("class EGL3::Modules::") && std::is_base_of_v<BaseModule, T>, bool> = true>
inline constexpr std::string_view module_name_v = type_name_v<T>.substr(sizeof("class EGL3::Modules::") - 1);
}

class ModuleList {
public:
ModuleList(const std::filesystem::path& BuilderPath, const std::filesystem::path& StoragePath);
Expand Down Expand Up @@ -35,7 +41,7 @@ namespace EGL3::Modules {
return *Ret;
}
}
EGL3_LOG(LogLevel::Critical, "Could not find module");
EGL3_ABORTF("Could not find module {}", Detail::module_name_v<T>);
}

template<typename T>
Expand All @@ -45,7 +51,7 @@ namespace EGL3::Modules {
return *Ret;
}
}
EGL3_LOG(LogLevel::Critical, "Could not find module");
EGL3_ABORTF("Could not find module {}", Detail::module_name_v<T>);
}

private:
Expand Down
2 changes: 1 addition & 1 deletion src/srv/MountedArchive.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ namespace EGL3::Service {
);
BytesToSelect -= SectionPartSize;
ItrDataOffset += SectionPartSize;
EGL3_CONDITIONAL_LOG(ItrDataOffset <= Itr->Size, LogLevel::Critical, "Invalid data offset");
EGL3_VERIFY(ItrDataOffset <= Itr->Size, "Invalid data offset");
} while (BytesToSelect);
SectionParts.emplace_back();
}
Expand Down
14 changes: 7 additions & 7 deletions src/srv/MountedDisk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

#include "../disk/interface.h"
#include "../utils/Align.h"
#include "../utils/Assert.h"
#include "../utils/Log.h"
#include "../utils/Random.h"
#include "../utils/mmio/MmioFile.h"
#include "xorfilter/xorfilter.h"
Expand Down Expand Up @@ -62,7 +62,7 @@ namespace EGL3::Service {

Data->Files.reserve(Files.size());
for (auto& File : Files) {
EGL3_CONDITIONAL_LOG(File.Path.size() < 256, LogLevel::Critical, "File path too long");
EGL3_VERIFY(File.Path.size() < 256, "File path too long");

auto& DataFile = Data->Files.emplace_back(EGL3File{
.size = File.FileSize,
Expand Down Expand Up @@ -141,11 +141,11 @@ namespace EGL3::Service {
.BlockAddress = 1,
.BlockCount = DiskSizeMegabytes * SectorsPerMegabyte - 1
};
EGL3_CONDITIONAL_LOG(SpdDefinePartitionTable(&Partition, 1, Data->MBRData) == ERROR_SUCCESS, LogLevel::Critical, "Could not create MBR data");
EGL3_VERIFY(SpdDefinePartitionTable(&Partition, 1, Data->MBRData) == ERROR_SUCCESS, "Could not create MBR data");

*(uint32_t*)(Data->MBRData + 440) = Data->DiskSignature;

EGL3_CONDITIONAL_LOG(EGL3CreateDisk("EGL3 Game", Data->Files.data(), Data->Files.size(), (void**)&Data->Disk), LogLevel::Critical, "Could not create disk");
EGL3_VERIFY(EGL3CreateDisk("EGL3 Game", Data->Files.data(), Data->Files.size(), (void**)&Data->Disk), "Could not create disk");

auto& DiskData = Data->Disk->get_data();
std::vector<uint64_t> DiskKeys;
Expand All @@ -155,7 +155,7 @@ namespace EGL3::Service {
DiskKeys.emplace_back(Key.first + 1);
}

EGL3_CONDITIONAL_LOG(Data->DiskFilter.Initialize(DiskKeys.data(), DiskKeys.size()), LogLevel::Critical, "Could not create xor filter");
EGL3_VERIFY(Data->DiskFilter.Initialize(DiskKeys.data(), DiskKeys.size()), "Could not create xor filter");
}

static UINT8 ClusterCache[4096];
Expand Down Expand Up @@ -313,7 +313,7 @@ namespace EGL3::Service {
// This can fail with error code 5
// https://github.com/billziss-gh/winspd/blob/master/doc/WinSpd-Tutorial.asciidoc#testing-the-integration-with-the-operating-system
// "This happens because mounting a storage unit requires administrator privileges."
EGL3_CONDITIONAL_LOG(SpdStorageUnitCreate(NULL, &Params, &DiskInterface, &Data->Unit) == ERROR_SUCCESS, LogLevel::Critical, "Could not create storage unit");
EGL3_VERIFY(SpdStorageUnitCreate(NULL, &Params, &DiskInterface, &Data->Unit) == ERROR_SUCCESS, "Could not create storage unit");

Data->Unit->UserContext = Data;
}
Expand All @@ -323,7 +323,7 @@ namespace EGL3::Service {
auto Data = (MountedData*)PrivateData;

SpdStorageUnitSetDebugLog(Data->Unit, LogFlags);
EGL3_CONDITIONAL_LOG(SpdStorageUnitStartDispatcher(Data->Unit, 1) == ERROR_SUCCESS, LogLevel::Critical, "Could not mount storage unit");
EGL3_VERIFY(SpdStorageUnitStartDispatcher(Data->Unit, 1) == ERROR_SUCCESS, "Could not mount storage unit");
SpdGuardSet(&Data->CloseGuard, Data->Unit);
}

Expand Down
10 changes: 5 additions & 5 deletions src/srv/pipe/server/Server.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "Server.h"

#include "../../../utils/streams/BufferStream.h"
#include "../../../utils/Assert.h"
#include "../../../utils/Log.h"

#define WIN32_LEAN_AND_MEAN
#define NOMINMAX
Expand All @@ -24,7 +24,7 @@ namespace EGL3::Service::Pipe {
void Server::HandleConnectionThread() {
PSID EveryoneSID = NULL;
SID_IDENTIFIER_AUTHORITY SIDAuthWorld = SECURITY_WORLD_SID_AUTHORITY;
EGL3_CONDITIONAL_LOG(AllocateAndInitializeSid(&SIDAuthWorld, 1, SECURITY_WORLD_RID, 0, 0, 0, 0, 0, 0, 0, &EveryoneSID), LogLevel::Critical, "Could not get SID");
EGL3_VERIFY(AllocateAndInitializeSid(&SIDAuthWorld, 1, SECURITY_WORLD_RID, 0, 0, 0, 0, 0, 0, 0, &EveryoneSID), "Could not get SID");

SECURITY_ATTRIBUTES SAttr{
.nLength = sizeof(SECURITY_ATTRIBUTES),
Expand All @@ -44,10 +44,10 @@ namespace EGL3::Service::Pipe {
};

PACL Acl = NULL;
EGL3_CONDITIONAL_LOG(SetEntriesInAcl(1, &Ace, NULL, &Acl) == ERROR_SUCCESS, LogLevel::Critical, "Could not set ACL entries");
EGL3_VERIFY(SetEntriesInAcl(1, &Ace, NULL, &Acl) == ERROR_SUCCESS, "Could not set ACL entries");
auto Sd = (PSECURITY_DESCRIPTOR)LocalAlloc(LPTR, SECURITY_DESCRIPTOR_MIN_LENGTH);
EGL3_CONDITIONAL_LOG(InitializeSecurityDescriptor(Sd, SECURITY_DESCRIPTOR_REVISION), LogLevel::Critical, "Could not allocate SD");
EGL3_CONDITIONAL_LOG(SetSecurityDescriptorDacl(Sd, TRUE, Acl, FALSE), LogLevel::Critical, "Could not set dacl");
EGL3_VERIFY(InitializeSecurityDescriptor(Sd, SECURITY_DESCRIPTOR_REVISION), "Could not allocate SD");
EGL3_VERIFY(SetSecurityDescriptorDacl(Sd, TRUE, Acl, FALSE), "Could not set dacl");

SAttr.lpSecurityDescriptor = Sd;

Expand Down
Loading

0 comments on commit b76563f

Please sign in to comment.