aboutsummaryrefslogtreecommitdiff
path: root/NorthstarDLL/sourceconsole.cpp
diff options
context:
space:
mode:
authorEmma Miler <emma.pi@protonmail.com>2022-11-12 15:39:39 +0100
committerGitHub <noreply@github.com>2022-11-12 14:39:39 +0000
commitbf09852285941e20a04731443d03c693e3f8ba2d (patch)
treea254973af94d819ab18b969e23045a309cbd15f7 /NorthstarDLL/sourceconsole.cpp
parentab5db7fde23ef6cd87fa8a7e07973179a80e02d4 (diff)
downloadNorthstarLauncher-bf09852285941e20a04731443d03c693e3f8ba2d.tar.gz
NorthstarLauncher-bf09852285941e20a04731443d03c693e3f8ba2d.zip
Logging improvements + Colours (new) (#320)
* log colours :) * commend the freopen stuff (it causes problems) * formatting * add explanatory comment * gaming maybe * move set pattern * ok this works now i think * trailing space :) * Revert "Merge branch 'main' into log-colours" This reverts commit d40b6496b7bd3b3f20f51cc2311b0369aeabe735, reversing changes made to a98bcc22e8961b325806f6a9ca85e64353fd574c. * Revert "Revert "Merge branch 'main' into log-colours"" This reverts commit da792245b1cd7d0ac9e22d5633770142a43ce10c. * fix shit maybe * fix shit but better * initial, still WIP * Add GetContextName_Short * colours for in game console * working, time to improve code * rename var + add a colour or two * whoops * change rpak filesystem to RP NATIVE * add RP NATIVE and NORTHSTAR tags * clang-format off because formatting * formatting 2 * formatting 3: the formattening * bruh * revert unnecessary change * improve comment * Set console title to show profile * pain * Made code not shit * Formatting and remove warning box * Update main.cpp * Formatting * More format changes * Again * Fix small things from code review * Remove empty line * renamed NATIVE_EN -> NATIVE_ENGINE * Update logging.cpp * Update sourceconsole.cpp Co-authored-by: ASpoonPlaysGames <66967891+ASpoonPlaysGames@users.noreply.github.com>
Diffstat (limited to 'NorthstarDLL/sourceconsole.cpp')
-rw-r--r--NorthstarDLL/sourceconsole.cpp29
1 files changed, 24 insertions, 5 deletions
diff --git a/NorthstarDLL/sourceconsole.cpp b/NorthstarDLL/sourceconsole.cpp
index ad31e09d..0048ac4c 100644
--- a/NorthstarDLL/sourceconsole.cpp
+++ b/NorthstarDLL/sourceconsole.cpp
@@ -25,14 +25,30 @@ void ConCommand_hideconsole(const CCommand& arg)
(*g_pSourceGameConsole)->Hide();
}
-void SourceConsoleSink::sink_it_(const spdlog::details::log_msg& msg)
+void SourceConsoleSink::custom_sink_it_(const custom_log_msg& msg)
{
if (!(*g_pSourceGameConsole)->m_bInitialized)
return;
spdlog::memory_buf_t formatted;
spdlog::sinks::base_sink<std::mutex>::formatter_->format(msg, formatted);
- (*g_pSourceGameConsole)->m_pConsole->m_pConsolePanel->ColorPrint(m_LogColours[msg.level], fmt::to_string(formatted).c_str());
+
+ // get message string
+ std::string str = fmt::to_string(formatted);
+
+ SourceColor levelColor = m_LogColours[msg.level];
+ std::string name {msg.logger_name.begin(), msg.logger_name.end()};
+
+ (*g_pSourceGameConsole)->m_pConsole->m_pConsolePanel->ColorPrint(msg.origin->SRCColor, ("[" + name + "]").c_str());
+ (*g_pSourceGameConsole)->m_pConsole->m_pConsolePanel->Print(" ");
+ (*g_pSourceGameConsole)->m_pConsole->m_pConsolePanel->ColorPrint(levelColor, ("[" + std::string(level_names[msg.level]) + "]").c_str());
+ (*g_pSourceGameConsole)->m_pConsole->m_pConsolePanel->Print(" ");
+ (*g_pSourceGameConsole)->m_pConsole->m_pConsolePanel->Print(fmt::to_string(formatted).c_str());
+}
+
+void SourceConsoleSink::sink_it_(const spdlog::details::log_msg& msg)
+{
+ throw std::runtime_error("sink_it_ called on SourceConsoleSink with pure log_msg. This is an error!");
}
void SourceConsoleSink::flush_() {}
@@ -58,9 +74,12 @@ void InitialiseConsoleOnInterfaceCreation()
// hook OnCommandSubmitted so we print inputted commands
OnCommandSubmittedHook.Dispatch((*g_pSourceGameConsole)->m_pConsole->m_vtable->OnCommandSubmitted);
- auto consoleLogger = std::make_shared<SourceConsoleSink>();
- consoleLogger->set_pattern("[%l] %v");
- spdlog::default_logger()->sinks().push_back(consoleLogger);
+ auto consoleSink = std::make_shared<SourceConsoleSink>();
+ if (g_bSpdLog_UseAnsiColor)
+ consoleSink->set_pattern("%v"); // no need to include the level in the game console, the text colour signifies it anyway
+ else
+ consoleSink->set_pattern("[%n] [%l] %v"); // no colour, so we should show the level for colourblind people
+ RegisterCustomSink(consoleSink);
}
ON_DLL_LOAD_CLIENT_RELIESON("client.dll", SourceConsole, ConCommand, (CModule module))