Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cherry pick logging refactor from primedev #617

Open
wants to merge 34 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
76b5049
logging refactor (#3)
F1F7Y Aug 9, 2023
d524bf2
convert newer logs to refactored logging
ASpoonPlaysGames Dec 18, 2023
88b5ee6
convert newer logs to refactored logging
ASpoonPlaysGames Dec 18, 2023
f05a8a4
Merge branch 'primedev-refactor/logging' of https://github.com/ASpoon…
ASpoonPlaysGames Dec 18, 2023
4d512b2
merge main
ASpoonPlaysGames Dec 18, 2023
8bf0a1b
convert new logs
ASpoonPlaysGames Dec 18, 2023
84108ce
formatting
ASpoonPlaysGames Dec 18, 2023
c89362b
fix compile
ASpoonPlaysGames Dec 18, 2023
06c8684
fix compile
ASpoonPlaysGames Dec 18, 2023
22ac194
formatting again
ASpoonPlaysGames Dec 18, 2023
10b1c72
Merge branch 'main' into primedev-refactor/logging
ASpoonPlaysGames Dec 20, 2023
5cbc5ec
When did that happen
ASpoonPlaysGames Dec 20, 2023
a216f66
This didn't get picked up in the merge because new file
ASpoonPlaysGames Dec 20, 2023
5a699d1
Also a new file
ASpoonPlaysGames Dec 20, 2023
b707512
Revert bad merge change
ASpoonPlaysGames Dec 20, 2023
0b6c0b9
This got missed in the cherry pick/merge somewhere
ASpoonPlaysGames Dec 20, 2023
7e074b8
How did this one get missed though
ASpoonPlaysGames Dec 20, 2023
50d85ac
Merge branch 'main' into primedev-refactor/logging
ASpoonPlaysGames Dec 20, 2023
bc4b053
Merge branch 'main' into primedev-refactor/logging
ASpoonPlaysGames Dec 20, 2023
1b9bd0e
Merge branch 'main' into primedev-refactor/logging
ASpoonPlaysGames Dec 20, 2023
0567f3f
Merge remote-tracking branch 'upstream/main' into primedev-refactor/l…
ASpoonPlaysGames Dec 27, 2023
f6771c0
Merge branch 'main' into primedev-refactor/logging
ASpoonPlaysGames Jan 3, 2024
959c328
Format Northstar.cmake
GeckoEidechse Jan 3, 2024
9e9b918
Merge branch 'main' into primedev-refactor/logging
ASpoonPlaysGames Jan 3, 2024
d4c6a55
move back to one log file
ASpoonPlaysGames Jan 18, 2024
e3ff8e7
Merge branch 'main' into primedev-refactor/logging
GeckoEidechse Jan 19, 2024
7e1512c
Merge branch 'main' into primedev-refactor/logging
ASpoonPlaysGames Jan 20, 2024
784cebb
fix conflicts
ASpoonPlaysGames Jan 27, 2024
4645a3d
Merge branch 'main' into primedev-refactor/logging
ASpoonPlaysGames Jan 28, 2024
88c5212
Merge branch 'main' into primedev-refactor/logging
GeckoEidechse Feb 4, 2024
84bd94a
big merge, hope i didnt miss any logs
ASpoonPlaysGames Feb 8, 2024
add6c4f
Merge branch 'primedev-refactor/logging' of https://github.com/ASpoon…
ASpoonPlaysGames Feb 8, 2024
1aee005
Merge branch 'main' into primedev-refactor/logging
GeckoEidechse Mar 3, 2024
90d36f2
fix build? idk builds locally for me
ASpoonPlaysGames Mar 3, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions primedev/Northstar.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ add_library(
"engine/runframe.cpp"
"logging/crashhandler.cpp"
"logging/crashhandler.h"
"logging/dbg.cpp"
"logging/dbg.h"
"logging/logging.cpp"
"logging/logging.h"
"logging/loghooks.cpp"
Expand Down
107 changes: 66 additions & 41 deletions primedev/client/audio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ CustomAudioManager g_CustomAudioManager;

EventOverrideData::EventOverrideData()
{
spdlog::warn("Initialised struct EventOverrideData without any data!");
Warning(eLog::AUDIO, "Initialised struct EventOverrideData without any data!\n");
LoadedSuccessfully = false;
}

Expand All @@ -32,7 +32,7 @@ EventOverrideData::EventOverrideData(const std::string& data, const fs::path& pa
{
if (data.length() <= 0)
{
spdlog::error("Failed reading audio override file {}: file is empty", path.string());
Error(eLog::AUDIO, NO_ERROR, "Failed reading audio override file %s: file is empty\n", path.string().c_str());
return;
}

Expand All @@ -41,10 +41,12 @@ EventOverrideData::EventOverrideData(const std::string& data, const fs::path& pa

if (!fs::exists(samplesFolder))
{
spdlog::error(
"Failed reading audio override file {}: samples folder doesn't exist; should be named the same as the definition file without "
"JSON extension.",
path.string());
Error(
eLog::AUDIO,
NO_ERROR,
"Failed reading audio override file %s: samples folder doesn't exist; should be named the same as the definition file without "
"JSON extension.\n",
path.string().c_str());
return;
}

Expand All @@ -54,9 +56,11 @@ EventOverrideData::EventOverrideData(const std::string& data, const fs::path& pa
// fail if parse error
if (dataJson.HasParseError())
{
spdlog::error(
"Failed reading audio override file {}: encountered parse error \"{}\" at offset {}",
path.string(),
Error(
eLog::AUDIO,
NO_ERROR,
"Failed reading audio override file %s: encountered parse error \"%s\" at offset %i\n",
path.string().c_str(),
GetParseError_En(dataJson.GetParseError()),
dataJson.GetErrorOffset());
return;
Expand All @@ -65,14 +69,18 @@ EventOverrideData::EventOverrideData(const std::string& data, const fs::path& pa
// fail if it's not a json obj (could be an array, string, etc)
if (!dataJson.IsObject())
{
spdlog::error("Failed reading audio override file {}: file is not a JSON object", path.string());
Error(eLog::AUDIO, NO_ERROR, "Failed reading audio override file %s: file is not a JSON object\n", path.string().c_str());
return;
}

// fail if no event ids given
if (!dataJson.HasMember("EventId"))
{
spdlog::error("Failed reading audio override file {}: JSON object does not have the EventId property", path.string());
Error(
eLog::AUDIO,
NO_ERROR,
"Failed reading audio override file %s: JSON object does not have the EventId property\n",
path.string().c_str());
return;
}

Expand All @@ -83,8 +91,11 @@ EventOverrideData::EventOverrideData(const std::string& data, const fs::path& pa
{
if (!eventId.IsString())
{
spdlog::error(
"Failed reading audio override file {}: EventId array has a value of invalid type, all must be strings", path.string());
Error(
eLog::AUDIO,
NO_ERROR,
"Failed reading audio override file %s: EventId array has a value of invalid type, all must be strings\n",
path.string().c_str());
return;
}

Expand All @@ -99,9 +110,11 @@ EventOverrideData::EventOverrideData(const std::string& data, const fs::path& pa
// incorrect type
else
{
spdlog::error(
"Failed reading audio override file {}: EventId property is of invalid type (must be a string or an array of strings)",
path.string());
Error(
eLog::AUDIO,
NO_ERROR,
"Failed reading audio override file %s: EventId property is of invalid type (must be a string or an array of strings)\n",
path.string().c_str());
return;
}

Expand All @@ -114,9 +127,11 @@ EventOverrideData::EventOverrideData(const std::string& data, const fs::path& pa
{
if (!eventId.IsString())
{
spdlog::error(
"Failed reading audio override file {}: EventIdRegex array has a value of invalid type, all must be strings",
path.string());
Error(
eLog::AUDIO,
NO_ERROR,
"Failed reading audio override file %s: EventIdRegex array has a value of invalid type, all must be strings\n",
path.string().c_str());
return;
}

Expand All @@ -128,7 +143,8 @@ EventOverrideData::EventOverrideData(const std::string& data, const fs::path& pa
}
catch (...)
{
spdlog::error("Malformed regex \"{}\" in audio override file {}", regex, path.string());
Error(
eLog::AUDIO, NO_ERROR, "Malformed regex \"%s\" in audio override file %s\n", regex.c_str(), path.string().c_str());
return;
}
}
Expand All @@ -143,16 +159,19 @@ EventOverrideData::EventOverrideData(const std::string& data, const fs::path& pa
}
catch (...)
{
spdlog::error("Malformed regex \"{}\" in audio override file {}", regex, path.string());
Error(eLog::AUDIO, NO_ERROR, "Malformed regex \"%s\" in audio override file %s\n", regex.c_str(), path.string().c_str());
return;
}
}
// incorrect type
else
{
spdlog::error(
"Failed reading audio override file {}: EventIdRegex property is of invalid type (must be a string or an array of strings)",
path.string());
Error(
eLog::AUDIO,
NO_ERROR,
"Failed reading audio override file %s: EventIdRegex property is of invalid type (must be a string or an array of "
"strings)\n",
path.string().c_str());
return;
}
}
Expand All @@ -161,7 +180,11 @@ EventOverrideData::EventOverrideData(const std::string& data, const fs::path& pa
{
if (!dataJson["AudioSelectionStrategy"].IsString())
{
spdlog::error("Failed reading audio override file {}: AudioSelectionStrategy property must be a string", path.string());
Error(
eLog::AUDIO,
NO_ERROR,
"Failed reading audio override file %s: AudioSelectionStrategy property must be a string\n",
path.string().c_str());
return;
}

Expand All @@ -177,9 +200,11 @@ EventOverrideData::EventOverrideData(const std::string& data, const fs::path& pa
}
else
{
spdlog::error(
"Failed reading audio override file {}: AudioSelectionStrategy string must be either \"sequential\" or \"random\"",
path.string());
Error(
eLog::AUDIO,
NO_ERROR,
"Failed reading audio override file %s: AudioSelectionStrategy string must be either \"sequential\" or \"random\"\n",
path.string().c_str());
return;
}
}
Expand All @@ -196,7 +221,7 @@ EventOverrideData::EventOverrideData(const std::string& data, const fs::path& pa

if (wavStream.fail())
{
spdlog::error("Failed reading audio sample {}", file.path().string());
Error(eLog::AUDIO, NO_ERROR, "Failed reading audio sample %s\n", file.path().string().c_str());
continue;
}

Expand All @@ -222,7 +247,7 @@ EventOverrideData::EventOverrideData(const std::string& data, const fs::path& pa
// would be weird if this got hit, since it would've worked previously
if (wavStream.fail())
{
spdlog::error("Failed async read of audio sample {}", pathString);
Error(eLog::AUDIO, NO_ERROR, "Failed async read of audio sample %s\n", pathString.c_str());
return;
}

Expand All @@ -231,7 +256,7 @@ EventOverrideData::EventOverrideData(const std::string& data, const fs::path& pa
wavStream.read(reinterpret_cast<char*>(data), fileSize);
wavStream.close();

spdlog::info("Finished async read of audio sample {}", pathString);
DevMsg(eLog::AUDIO, "Finished async read of audio sample %s\n", pathString.c_str());
});

readThread.detach();
Expand All @@ -252,9 +277,9 @@ EventOverrideData::EventOverrideData(const std::string& data, const fs::path& pa
*/

if (Samples.size() == 0)
spdlog::warn("Audio override {} has no valid samples! Sounds will not play for this event.", path.string());
Warning(eLog::AUDIO, "Audio override %s has no valid samples! Sounds will not play for this event.\n", path.string().c_str());

spdlog::info("Loaded audio override file {}", path.string());
DevMsg(eLog::AUDIO, "Loaded audio override file %s\n", path.string().c_str());

LoadedSuccessfully = true;
}
Expand All @@ -270,7 +295,7 @@ bool CustomAudioManager::TryLoadAudioOverride(const fs::path& defPath)
// fail if no audio json
if (jsonStream.fail())
{
spdlog::warn("Unable to read audio override from file {}", defPath.string());
Warning(eLog::AUDIO, "Unable to read audio override from file %s\n", defPath.string().c_str());
return false;
}

Expand All @@ -286,13 +311,13 @@ bool CustomAudioManager::TryLoadAudioOverride(const fs::path& defPath)

for (const std::string& eventId : data->EventIds)
{
spdlog::info("Registering sound event {}", eventId);
DevMsg(eLog::AUDIO, "Registering sound event %s\n", eventId.c_str());
m_loadedAudioOverrides.insert({eventId, data});
}

for (const auto& eventIdRegexData : data->EventIdsRegex)
{
spdlog::info("Registering sound event regex {}", eventIdRegexData.first);
DevMsg(eLog::AUDIO, "Registering sound event regex %s\n", eventIdRegexData.first.c_str());
m_loadedAudioOverridesRegex.insert({eventIdRegexData.first, data});
}

Expand Down Expand Up @@ -374,7 +399,7 @@ bool, __fastcall, (void* sample, void* audioBuffer, unsigned int audioBufferLeng
const char* eventName = pszAudioEventName;

if (Cvar_ns_print_played_sounds->GetInt() > 0)
spdlog::info("[AUDIO] Playing event {}", eventName);
DevMsg(eLog::AUDIO, "Playing event %s\n", eventName);

auto iter = g_CustomAudioManager.m_loadedAudioOverrides.find(eventName);
std::shared_ptr<EventOverrideData> overrideData;
Expand Down Expand Up @@ -441,7 +466,7 @@ bool, __fastcall, (void* sample, void* audioBuffer, unsigned int audioBufferLeng
}

if (!dat)
spdlog::warn("Could not get sample data from override struct for event {}! Shouldn't happen", eventName);
Warning(eLog::AUDIO, "Could not get sample data from override struct for event %s! Shouldn't happen\n", eventName);
else
{
data = dat->second.get();
Expand All @@ -451,7 +476,7 @@ bool, __fastcall, (void* sample, void* audioBuffer, unsigned int audioBufferLeng

if (!data)
{
spdlog::warn("Could not fetch override sample data for event {}! Using original data instead.", eventName);
Warning(eLog::AUDIO, "Could not fetch override sample data for event {}! Using original data instead.\n", eventName);
return LoadSampleMetadata(sample, audioBuffer, audioBufferLength, audioType);
}

Expand All @@ -465,7 +490,7 @@ bool, __fastcall, (void* sample, void* audioBuffer, unsigned int audioBufferLeng
// 64 - Auto-detect sample type
bool res = LoadSampleMetadata(sample, audioBuffer, audioBufferLength, 64);
if (!res)
spdlog::error("LoadSampleMetadata failed! The game will crash :(");
Error(eLog::AUDIO, NO_ERROR, "LoadSampleMetadata failed! The game will crash :(\n");

return res;
}
Expand All @@ -487,7 +512,7 @@ void, __fastcall, (int level, const char* string))
if (!Cvar_mileslog_enable->GetBool())
return;

spdlog::info("[MSS] {} - {}", level, string);
DevMsg(eLog::AUDIO, "%i - %s\n", level, string);
}

ON_DLL_LOAD_RELIESON("engine.dll", MilesLogFuncHooks, ConVar, (CModule module))
Expand Down
2 changes: 1 addition & 1 deletion primedev/client/clientvideooverrides.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ void*, __fastcall, (const char* path, uint32_t flags))
// clang-format on
{
std::string filename(fs::path(path).filename().string());
spdlog::info("BinkOpen {}", filename);
DevMsg(eLog::VIDEO, "BinkOpen %s\n", filename);

// figure out which mod is handling the bink
Mod* fileOwner = nullptr;
Expand Down
2 changes: 1 addition & 1 deletion primedev/client/debugoverlay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ void, __fastcall, (OverlayBase_t * pOverlay))
break;
default:
{
spdlog::warn("Unimplemented overlay type {}", pOverlay->m_Type);
Warning(eLog::ENGINE, "Unimplemented overlay type %i\n", pOverlay->m_Type);
}
break;
}
Expand Down
27 changes: 16 additions & 11 deletions primedev/client/languagehooks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,15 @@ char*, __fastcall, ())
{
if (!CheckLangAudioExists((char*)forcedLanguage))
{
spdlog::info(
"User tried to force the language (-language) to \"{}\", but audio for this language doesn't exist and the game is bound "
"to error, falling back to next option...",
Warning(
eLog::AUDIO,
"User tried to force the language (-language) to \"%s\", but audio for this language doesn't exist and the game is bound "
"to error, falling back to next option...\n",
forcedLanguage);
}
else
{
spdlog::info("User forcing the language (-language) to: {}", forcedLanguage);
DevMsg(eLog::AUDIO, "User forcing the language (-language) to: %s\n", forcedLanguage);
strncpy(ingameLang1, forcedLanguage, 256);
return ingameLang1;
}
Expand All @@ -81,12 +82,14 @@ char*, __fastcall, ())
{
if (strcmp(lang, "russian") !=
0) // don't log for "russian" since it's the default and that means Origin detection just didn't change it most likely
spdlog::info(
"Origin detected language \"{}\", but we do not have audio for it installed, falling back to the next option", lang);
DevMsg(
eLog::AUDIO,
"Origin detected language \"%s\", but we do not have audio for it installed, falling back to the next option\n",
lang);
}
else
{
spdlog::info("Origin detected language: {}", lang);
DevMsg(eLog::AUDIO, "Origin detected language: %s\n", lang);
return lang;
}
}
Expand All @@ -95,13 +98,15 @@ char*, __fastcall, ())
// defaulting to Russian
canOriginDictateLang = false; // Origin has no say anymore, we will fallback to user's system setup language
auto lang = GetGameLanguage();
spdlog::info("Detected system language: {}", lang);
DevMsg(eLog::AUDIO, "Detected system language: %s\n", lang);
if (!CheckLangAudioExists(lang))
{
spdlog::warn("Caution, audio for this language does NOT exist. You might want to override your game language with -language "
"command line option.");
Warning(
eLog::AUDIO,
"Caution, audio for this language does NOT exist. You might want to override your game language with -language command line "
"option.\n");
auto lang = GetAnyInstalledAudioLanguage();
spdlog::warn("Falling back to the first installed audio language: {}", lang.c_str());
Warning(eLog::AUDIO, "Falling back to the first installed audio language: %s\n", lang.c_str());
strncpy(ingameLang1, lang.c_str(), 256);
return ingameLang1;
}
Expand Down
4 changes: 2 additions & 2 deletions primedev/client/latencyflex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@ ON_DLL_LOAD_CLIENT_RELIESON("client.dll", LatencyFlex, ConVar, (CModule module))
reinterpret_cast<void (*)()>(reinterpret_cast<void*>(GetProcAddress(pLfxModule, "winelfx_WaitAndBeginFrame")));
else
{
spdlog::info("Unable to load LatencyFleX library, LatencyFleX disabled.");
Warning(eLog::NS, "Unable to load LatencyFleX library, LatencyFleX disabled.\n");
return;
}

AUTOHOOK_DISPATCH()

spdlog::info("LatencyFleX initialized.");
DevMsg(eLog::NS, "LatencyFleX initialized.\n");
Cvar_r_latencyflex = new ConVar("r_latencyflex", "1", FCVAR_ARCHIVE, "Whether or not to use LatencyFleX input latency reduction.");
}
2 changes: 1 addition & 1 deletion primedev/client/localchatwriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ void LocalChatWriter::InsertChar(wchar_t ch)

void LocalChatWriter::InsertText(const char* str)
{
spdlog::info(str);
DevMsg(eLog::CHAT, "%s\n", str);

WCHAR messageUnicode[288];
ConvertANSIToUnicode(str, -1, messageUnicode, 274);
Expand Down
Loading
Loading