diff options
author | BobTheBob <32057864+BobTheBob9@users.noreply.github.com> | 2021-07-17 22:33:00 +0100 |
---|---|---|
committer | BobTheBob <32057864+BobTheBob9@users.noreply.github.com> | 2021-07-17 22:33:00 +0100 |
commit | ca5db71e8215a6c5660fe03088a6d7349f55f817 (patch) | |
tree | 534b79d2599475b1da3edb4f232223d9e32d3174 /NorthstarDedicatedTest/logging.cpp | |
parent | 51d3d4a40c8579e29571bc80d35bbb62fa50661b (diff) | |
download | NorthstarLauncher-ca5db71e8215a6c5660fe03088a6d7349f55f817.tar.gz NorthstarLauncher-ca5db71e8215a6c5660fe03088a6d7349f55f817.zip |
add support for custom convars and concommands
Diffstat (limited to 'NorthstarDedicatedTest/logging.cpp')
-rw-r--r-- | NorthstarDedicatedTest/logging.cpp | 47 |
1 files changed, 20 insertions, 27 deletions
diff --git a/NorthstarDedicatedTest/logging.cpp b/NorthstarDedicatedTest/logging.cpp index 021613d9..85b92c0c 100644 --- a/NorthstarDedicatedTest/logging.cpp +++ b/NorthstarDedicatedTest/logging.cpp @@ -2,33 +2,17 @@ #include "logging.h" #include "context.h" #include "dedicated.h" +#include "sourceconsole.h" #include <vector> #include <iostream> #include <chrono> -std::vector<LoggingSink> loggingSinks; - -void Log(Context context, char* fmt, ...) +void InitialiseLogging() { - va_list args; - va_start(args, fmt); + AllocConsole(); + freopen("CONOUT$", "w", stdout); - Log(context, fmt, args); - va_end(args); -} - -void Log(Context context, char* fmt, va_list args) -{ - char buf[1024]; - vsnprintf_s(buf, _TRUNCATE, fmt, args); - - for (LoggingSink& sink : loggingSinks) - sink(context, fmt); -} - -void AddLoggingSink(LoggingSink sink) -{ - loggingSinks.push_back(sink); + spdlog::default_logger()->set_pattern("[%H:%M:%S] [%l] %v"); } // default logging sink @@ -39,14 +23,23 @@ void DefaultLoggingSink(Context context, char* message) char timeBuf[10]; strftime(timeBuf, sizeof(timeBuf), "%X", localTime); - std::cout << "[" << timeBuf << "] "; - if (context != NONE) - std::cout << "[" << GetContextName(context) << "] "; + std::string messageStr; - std::cout << message; + messageStr.append("["); + messageStr.append(timeBuf); + messageStr.append("] "); - if (!IsDedicated()) + if (context != NONE) { - + messageStr.append("["); + messageStr.append(GetContextName(context)); + messageStr.append("] "); } + + messageStr.append(message); + std::cout << messageStr; + + // dont need to check dedi since this won't be initialised on dedi anyway + if ((*g_SourceGameConsole)->m_bInitialized) + (*g_SourceGameConsole)->m_pConsole->m_pConsolePanel->Print(messageStr.c_str()); }
\ No newline at end of file |