diff options
| author | Stefan Boberg <[email protected]> | 2021-09-09 11:03:49 +0200 |
|---|---|---|
| committer | Stefan Boberg <[email protected]> | 2021-09-09 11:03:49 +0200 |
| commit | 090d89eb62d660d6c854a5f8bc44293004d22462 (patch) | |
| tree | 6c6722ad99c0c2a0c764eeec7ecb76a39ffcce1c | |
| parent | Delete .zenroot (no longer useful) (diff) | |
| parent | printf -> zencore logging (diff) | |
| download | zen-090d89eb62d660d6c854a5f8bc44293004d22462.tar.xz zen-090d89eb62d660d6c854a5f8bc44293004d22462.zip | |
Merge branch 'main' of https://github.com/EpicGames/zen
| -rw-r--r-- | zencore/httpserver.cpp | 3 | ||||
| -rw-r--r-- | zencore/include/zencore/logging.h | 14 | ||||
| -rw-r--r-- | zencore/logging.cpp | 57 | ||||
| -rw-r--r-- | zencore/zencore.vcxproj | 1 | ||||
| -rw-r--r-- | zencore/zencore.vcxproj.filters | 1 | ||||
| -rw-r--r-- | zenserver/config.cpp | 6 | ||||
| -rw-r--r-- | zenserver/diag/logging.cpp | 66 | ||||
| -rw-r--r-- | zenserver/diag/logging.h | 10 |
8 files changed, 104 insertions, 54 deletions
diff --git a/zencore/httpserver.cpp b/zencore/httpserver.cpp index aa7d96772..d7e6a875f 100644 --- a/zencore/httpserver.cpp +++ b/zencore/httpserver.cpp @@ -13,6 +13,7 @@ #include <zencore/compactbinary.h> #include <zencore/compactbinarypackage.h> #include <zencore/iobuffer.h> +#include <zencore/logging.h> #include <zencore/refcount.h> #include <zencore/stream.h> #include <zencore/string.h> @@ -965,7 +966,7 @@ HttpSysServer::Run(bool TestMode) { if (TestMode == false) { - printf("Zen Server running. Press ESC or Q to quit\n"); + zen::logging::ConsoleLog().info("Zen Server running. Press ESC or Q to quit"); } do 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..ddef83c02 100644 --- a/zenserver/config.cpp +++ b/zenserver/config.cpp @@ -85,7 +85,7 @@ ParseGlobalCliOptions(int argc, char* argv[], ZenServerOptions& GlobalOptions, Z "m", "mesh", "Enable mesh network", - cxxopts::value<bool>(ServiceConfig.MeshEnabled)->default_value("true"), + cxxopts::value<bool>(ServiceConfig.MeshEnabled)->default_value("false"), ""); options.add_option("diagnostics", @@ -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 89ed4ac6a..796a15d01 100644 --- a/zenserver/diag/logging.cpp +++ b/zenserver/diag/logging.cpp @@ -4,6 +4,8 @@ #include "config.h" +#include <spdlog/async.h> +#include <spdlog/async_logger.h> #include <spdlog/pattern_formatter.h> #include <spdlog/sinks/ansicolor_sink.h> #include <spdlog/sinks/basic_file_sink.h> @@ -187,13 +189,33 @@ EnableVTMode() void InitializeLogging(const ZenServerOptions& GlobalOptions) { + zen::logging::InitializeLogging(); + EnableVTMode(); std::filesystem::path LogPath = GlobalOptions.DataDir / "logs/zenserver.log"; - spdlog::level::level_enum LogLevel = spdlog::level::debug; + bool IsAsync = true; + spdlog::level::level_enum LogLevel = spdlog::level::info; + + if (GlobalOptions.IsDebug) + { + LogLevel = spdlog::level::debug; + IsAsync = false; + } + + if (IsAsync) + { + const int QueueSize = 8192; + const int ThreadCount = 1; + spdlog::init_thread_pool(QueueSize, ThreadCount); + + auto AsyncLogger = spdlog::create_async<spdlog::sinks::ansicolor_stdout_sink_mt>("main"); + spdlog::set_default_logger(AsyncLogger); + } // Sinks + auto ConsoleSink = std::make_shared<spdlog::sinks::ansicolor_stdout_sink_mt>(); auto FileSink = std::make_shared<spdlog::sinks::basic_file_sink_mt>(zen::WideToUtf8(LogPath.c_str()), /* truncate */ true); @@ -201,9 +223,11 @@ InitializeLogging(const ZenServerOptions& GlobalOptions) auto DefaultLogger = spdlog::default_logger(); auto& Sinks = spdlog::default_logger()->sinks(); Sinks.clear(); + Sinks.push_back(ConsoleSink); Sinks.push_back(FileSink); DefaultLogger->set_level(LogLevel); + DefaultLogger->flush_on(spdlog::level::err); // Jupiter - only log HTTP traffic to file auto JupiterLogger = std::make_shared<spdlog::logger>("jupiter", FileSink); @@ -221,43 +245,5 @@ InitializeLogging(const ZenServerOptions& GlobalOptions) void ShutdownLogging() { - spdlog::drop_all(); - spdlog::shutdown(); + zen::logging::ShutdownLogging(); } - -spdlog::logger& -ConsoleLog() -{ - static auto ConLogger = spdlog::stdout_color_mt("console"); - - ConLogger->set_pattern("%v"); - - return *ConLogger; -} - -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 |