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

Logging refactor #504

Draft
wants to merge 60 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
60 commits
Select commit Hold shift + click to select a range
b0aceda
Add basic logging functions
F1F7Y Jul 2, 2023
6a30460
Move to new logging functions
F1F7Y Jul 7, 2023
f7d0fa8
Fix compilation
F1F7Y Jul 8, 2023
66d9f47
Gracefully terminate when our directory isnt writable
F1F7Y Jul 8, 2023
820c6b1
Add `-wconsole` argument
F1F7Y Jul 8, 2023
fe2d0c0
Use new functions in more places
F1F7Y Jul 8, 2023
3a346e9
Add helper funcs
F1F7Y Jul 8, 2023
74cc8ab
Merge branch 'main' into PR/logging-refactor
F1F7Y Jul 8, 2023
26a8aeb
Thanks spoon
F1F7Y Jul 8, 2023
7c29568
Print to game console
F1F7Y Jul 8, 2023
e265db1
Stop using NS::log and spdlog:: in squirrel
F1F7Y Jul 8, 2023
90281cb
add log context string to each print
F1F7Y Jul 8, 2023
77c3f61
Print to win terminal
F1F7Y Jul 8, 2023
6e54134
Don't automatically add eol
F1F7Y Jul 8, 2023
c168d44
Properly shutdown spdlog
F1F7Y Jul 8, 2023
6dd3599
Fixup some messages
F1F7Y Jul 8, 2023
25b4abd
Formatting
F1F7Y Jul 8, 2023
65497ec
Use spaces in CMakeLists.txt
F1F7Y Jul 8, 2023
8dbfcb9
Formatting
F1F7Y Jul 8, 2023
23fadef
Use new funcs fol plugin log
F1F7Y Jul 9, 2023
c2a0149
Always allocate console when we'rea dedi
F1F7Y Jul 9, 2023
45102e1
Update dedilogtoclient
F1F7Y Jul 9, 2023
7287ef2
Remove old logging classes
F1F7Y Jul 9, 2023
0458986
Fix PLUGIN_LOG
F1F7Y Jul 9, 2023
a972f36
Color logging
F1F7Y Jul 9, 2023
48222f7
Don't log searchpath
F1F7Y Jul 9, 2023
c6d527a
Fix masterserver error log
F1F7Y Jul 9, 2023
16642b1
Properly break in switch in spew func
F1F7Y Jul 9, 2023
f9c98af
Remove comment
F1F7Y Jul 9, 2023
f2ae51f
Log to disk
F1F7Y Jul 9, 2023
c5a0ffd
Format
F1F7Y Jul 9, 2023
387f8b1
Terminate on fatal error call
F1F7Y Jul 9, 2023
687b89f
Improve doc comments in `dbg.cpp`
F1F7Y Jul 9, 2023
8c51e27
Use displayName for plugin logging
F1F7Y Jul 9, 2023
4172434
Improve more doc comments
F1F7Y Jul 9, 2023
9cdd908
add `-nologfiles` argument
F1F7Y Jul 9, 2023
e4ee674
Rename `g_bSpdLog_UseAnsiColor` to `g_bConsole_UseAnsiColor`
F1F7Y Jul 9, 2023
2388eef
Add plugin color
F1F7Y Jul 9, 2023
3637686
Adjust colors
F1F7Y Jul 9, 2023
9e840f3
Add missing newlines
F1F7Y Jul 9, 2023
f7167b3
Fix specifier
F1F7Y Jul 10, 2023
89d0e74
Separate SQ_GetLogContext into native and script versions
F1F7Y Jul 10, 2023
7dbb2ee
Replace spdlog::info i missed
F1F7Y Jul 10, 2023
91f5a5b
Format
F1F7Y Jul 11, 2023
28300fc
Only close console once gamewindow has been created
F1F7Y Jul 13, 2023
a6d19aa
Improve log categories
F1F7Y Jul 14, 2023
8f23078
Fix compile error context
F1F7Y Jul 14, 2023
fd1cd15
Fix missed format in `scriptdatatables.cpp`
F1F7Y Jul 15, 2023
3530767
Rename `pszAnsiString` to `svAnsiString`
F1F7Y Jul 16, 2023
bfd4823
Add lock guard
F1F7Y Jul 16, 2023
c8dba91
Don't try to show messagebox when we're a dedicated server on error
F1F7Y Jul 16, 2023
b4981b0
Rename `fLogger` to `pLogger`
F1F7Y Jul 16, 2023
fff47a2
Merge branch 'main' into PR/logging-refactor
F1F7Y Jul 19, 2023
870ebd0
Use new funcs for system info
F1F7Y Jul 19, 2023
8c7e4e5
Rename `StartupLog` to `Sys_PrintOSVer`
F1F7Y Jul 19, 2023
ec01c9e
Initilaze `g_svLogDirectory` directly in `InitilazeNorthstar`
F1F7Y Jul 19, 2023
fe22df0
Cleanup `InitilaseNorthstar`
F1F7Y Jul 19, 2023
76dc30c
Add back ntdll check
F1F7Y Jul 19, 2023
09ab061
Merge branch 'main' into PR/logging-refactor
F1F7Y Jul 27, 2023
973b2db
Merge branch 'main' into PR/logging-refactor
F1F7Y Jul 29, 2023
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 NorthstarDLL/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ add_library(NorthstarDLL SHARED
"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 NorthstarDLL/client/audio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,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 @@ -35,7 +35,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 @@ -44,10 +44,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 @@ -57,9 +59,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 @@ -68,14 +72,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 @@ -86,8 +94,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 @@ -102,9 +113,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 @@ -117,9 +130,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 @@ -131,7 +146,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 @@ -146,16 +162,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 @@ -164,7 +183,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 @@ -180,9 +203,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 @@ -199,7 +224,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 @@ -225,7 +250,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 @@ -234,7 +259,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 @@ -255,9 +280,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 @@ -273,7 +298,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 @@ -289,13 +314,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 @@ -393,7 +418,7 @@ bool __declspec(noinline) __fastcall LoadSampleMetadata_Internal(
char* eventName = (char*)parentEvent + 0x110;

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 @@ -460,7 +485,7 @@ bool __declspec(noinline) __fastcall LoadSampleMetadata_Internal(
}

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 @@ -470,7 +495,7 @@ bool __declspec(noinline) __fastcall LoadSampleMetadata_Internal(

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 @@ -484,7 +509,7 @@ bool __declspec(noinline) __fastcall LoadSampleMetadata_Internal(
// 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 @@ -494,7 +519,7 @@ AUTOHOOK(MilesLog, client.dll + 0x57DAD0,
void, __fastcall, (int level, const char* string))
// clang-format on
{
spdlog::info("[MSS] {} - {}", level, string);
DevMsg(eLog::AUDIO, "%i - %s\n", level, string);
}

ON_DLL_LOAD_CLIENT_RELIESON("client.dll", AudioHooks, ConVar, (CModule module))
Expand Down
2 changes: 1 addition & 1 deletion NorthstarDLL/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
27 changes: 16 additions & 11 deletions NorthstarDLL/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 NorthstarDLL/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 NorthstarDLL/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