aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStefan Boberg <[email protected]>2021-09-08 19:10:59 +0200
committerStefan Boberg <[email protected]>2021-09-08 19:21:21 +0200
commite44740f9bf2846e69e8c01d7b1f7a7b8545af6b6 (patch)
treefaba4bdd2810150d5c9e991998d2b55cb5c8c1be
parentMerge branch 'main' of https://github.com/EpicGames/zen (diff)
downloadzen-e44740f9bf2846e69e8c01d7b1f7a7b8545af6b6.tar.xz
zen-e44740f9bf2846e69e8c01d7b1f7a7b8545af6b6.zip
Moved a bunch of logging code into zencore
-rw-r--r--zencore/include/zencore/logging.h14
-rw-r--r--zencore/logging.cpp57
-rw-r--r--zencore/zencore.vcxproj1
-rw-r--r--zencore/zencore.vcxproj.filters1
-rw-r--r--zenserver/config.cpp4
-rw-r--r--zenserver/diag/logging.cpp47
-rw-r--r--zenserver/diag/logging.h10
7 files changed, 78 insertions, 56 deletions
diff --git a/zencore/include/zencore/logging.h b/zencore/include/zencore/logging.h
index e77314178..7a08cc48b 100644
--- a/zencore/include/zencore/logging.h
+++ b/zencore/include/zencore/logging.h
@@ -7,3 +7,17 @@
#include <spdlog/spdlog.h>
#include "postwindows.h"
// clang-format on
+
+#include <string_view>
+
+namespace zen::logging {
+
+spdlog::logger& Default();
+spdlog::logger& ConsoleLog();
+spdlog::logger& Get(std::string_view Name);
+
+void InitializeLogging();
+void ShutdownLogging();
+
+
+} // namespace zen::logging
diff --git a/zencore/logging.cpp b/zencore/logging.cpp
new file mode 100644
index 000000000..89d588650
--- /dev/null
+++ b/zencore/logging.cpp
@@ -0,0 +1,57 @@
+#include "zencore/logging.h"
+
+#include <spdlog/sinks/stdout_color_sinks.h>
+
+namespace zen::logging {
+
+spdlog::logger&
+Default()
+{
+ return *spdlog::default_logger();
+}
+
+spdlog::logger&
+Get(std::string_view Name)
+{
+ std::shared_ptr<spdlog::logger> Logger = spdlog::get(std::string(Name));
+ if (!Logger)
+ {
+ Logger = std::make_shared<spdlog::logger>(std::string(Name),
+ begin(spdlog::default_logger()->sinks()),
+ end(spdlog::default_logger()->sinks()));
+
+ Logger->set_level(spdlog::default_logger()->level());
+ spdlog::register_logger(Logger);
+ }
+
+ return *Logger;
+}
+
+std::once_flag ConsoleInitFlag;
+std::shared_ptr<spdlog::logger> ConLogger;
+
+spdlog::logger&
+ConsoleLog()
+{
+ std::call_once(ConsoleInitFlag, [&] {
+ ConLogger = spdlog::stdout_color_mt("console");
+
+ ConLogger->set_pattern("%v");
+ });
+
+ return *ConLogger;
+}
+
+void
+InitializeLogging()
+{
+}
+
+void
+ShutdownLogging()
+{
+ spdlog::drop_all();
+ spdlog::shutdown();
+}
+
+} // namespace zen::logging
diff --git a/zencore/zencore.vcxproj b/zencore/zencore.vcxproj
index 6da8794b3..bf35f8f5a 100644
--- a/zencore/zencore.vcxproj
+++ b/zencore/zencore.vcxproj
@@ -167,6 +167,7 @@
<ClCompile Include="httpserver.cpp" />
<ClCompile Include="iohash.cpp" />
<ClCompile Include="iothreadpool.cpp" />
+ <ClCompile Include="logging.cpp" />
<ClCompile Include="md5.cpp" />
<ClCompile Include="memory.cpp" />
<ClCompile Include="refcount.cpp" />
diff --git a/zencore/zencore.vcxproj.filters b/zencore/zencore.vcxproj.filters
index 8b105fc31..b1b1b9359 100644
--- a/zencore/zencore.vcxproj.filters
+++ b/zencore/zencore.vcxproj.filters
@@ -76,6 +76,7 @@
<ClCompile Include="compress.cpp" />
<ClCompile Include="compositebuffer.cpp" />
<ClCompile Include="crc32.cpp" />
+ <ClCompile Include="logging.cpp" />
</ItemGroup>
<ItemGroup>
<Filter Include="CAS">
diff --git a/zenserver/config.cpp b/zenserver/config.cpp
index 904e613a4..665c567cc 100644
--- a/zenserver/config.cpp
+++ b/zenserver/config.cpp
@@ -178,14 +178,14 @@ ParseGlobalCliOptions(int argc, char* argv[], ZenServerOptions& GlobalOptions, Z
if (result.count("help"))
{
- ConsoleLog().info("{}", options.help());
+ zen::logging::ConsoleLog().info("{}", options.help());
exit(0);
}
}
catch (cxxopts::OptionParseException& e)
{
- ConsoleLog().error("Error parsing zenserver arguments: {}\n\n{}", e.what(), options.help());
+ zen::logging::ConsoleLog().error("Error parsing zenserver arguments: {}\n\n{}", e.what(), options.help());
throw;
}
diff --git a/zenserver/diag/logging.cpp b/zenserver/diag/logging.cpp
index a5a4edfc0..796a15d01 100644
--- a/zenserver/diag/logging.cpp
+++ b/zenserver/diag/logging.cpp
@@ -189,6 +189,8 @@ EnableVTMode()
void
InitializeLogging(const ZenServerOptions& GlobalOptions)
{
+ zen::logging::InitializeLogging();
+
EnableVTMode();
std::filesystem::path LogPath = GlobalOptions.DataDir / "logs/zenserver.log";
@@ -243,48 +245,5 @@ InitializeLogging(const ZenServerOptions& GlobalOptions)
void
ShutdownLogging()
{
- spdlog::drop_all();
- spdlog::shutdown();
-}
-
-std::once_flag ConsoleInitFlag;
-std::shared_ptr<spdlog::logger> ConLogger;
-
-spdlog::logger&
-ConsoleLog()
-{
- std::call_once(ConsoleInitFlag, [&] {
- ConLogger = spdlog::stdout_color_mt("console");
-
- ConLogger->set_pattern("%v");
- });
-
- return *ConLogger;
+ zen::logging::ShutdownLogging();
}
-
-namespace zen::logging {
-
-spdlog::logger&
-Default()
-{
- return *spdlog::default_logger();
-}
-
-spdlog::logger&
-Get(std::string_view Name)
-{
- std::shared_ptr<spdlog::logger> Logger = spdlog::get(std::string(Name));
- if (!Logger)
- {
- Logger = std::make_shared<spdlog::logger>(std::string(Name),
- begin(spdlog::default_logger()->sinks()),
- end(spdlog::default_logger()->sinks()));
-
- Logger->set_level(spdlog::default_logger()->level());
- spdlog::register_logger(Logger);
- }
-
- return *Logger;
-}
-
-} // namespace zen::logging
diff --git a/zenserver/diag/logging.h b/zenserver/diag/logging.h
index bc93898ad..8df49f842 100644
--- a/zenserver/diag/logging.h
+++ b/zenserver/diag/logging.h
@@ -8,13 +8,3 @@ struct ZenServerOptions;
void InitializeLogging(const ZenServerOptions& GlobalOptions);
void ShutdownLogging();
-
-spdlog::logger& ConsoleLog();
-
-namespace zen::logging {
-
-spdlog::logger& Default();
-
-spdlog::logger& Get(std::string_view Name);
-
-} // namespace zen::logging