diff options
| author | Stefan Boberg <[email protected]> | 2021-09-17 23:32:05 +0200 |
|---|---|---|
| committer | Stefan Boberg <[email protected]> | 2021-09-17 23:32:05 +0200 |
| commit | a79a7830472e9b994eacbb22c1a9fd223c4cc2c7 (patch) | |
| tree | c7c8d652be09d4ab66f08ab3fe268f037374401e | |
| parent | zenserver can now run as a Windows service. We'll still need to improve how d... (diff) | |
| download | zen-a79a7830472e9b994eacbb22c1a9fd223c4cc2c7.tar.xz zen-a79a7830472e9b994eacbb22c1a9fd223c4cc2c7.zip | |
Changed file logging to use a rotating log strategy
| -rw-r--r-- | zenserver/diag/logging.cpp | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/zenserver/diag/logging.cpp b/zenserver/diag/logging.cpp index 48c87dd68..1df35fc14 100644 --- a/zenserver/diag/logging.cpp +++ b/zenserver/diag/logging.cpp @@ -9,7 +9,9 @@ #include <spdlog/pattern_formatter.h> #include <spdlog/sinks/ansicolor_sink.h> #include <spdlog/sinks/basic_file_sink.h> +#include <spdlog/sinks/daily_file_sink.h> #include <spdlog/sinks/msvc_sink.h> +#include <spdlog/sinks/rotating_file_sink.h> #include <spdlog/sinks/stdout_color_sinks.h> #include <spdlog/spdlog.h> #include <zencore/string.h> @@ -224,7 +226,19 @@ InitializeLogging(const ZenServerOptions& GlobalOptions) // 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); + +#if 0 + auto FileSink = std::make_shared<spdlog::sinks::daily_file_sink_mt>(zen::WideToUtf8(LogPath.c_str()), + 0, + 0, + /* truncate */ false, + uint16_t(/* max files */ 14)); +#else + auto FileSink = std::make_shared<spdlog::sinks::rotating_file_sink_mt>(zen::WideToUtf8(LogPath.c_str()), + /* max size */ 128 * 1024 * 1024, + /* max files */ 16, + /* rotate on open */ true); +#endif // Default @@ -250,6 +264,8 @@ InitializeLogging(const ZenServerOptions& GlobalOptions) spdlog::register_logger(JupiterLogger); JupiterLogger->set_level(LogLevel); + // Zen - only log HTTP traffic to file + auto ZenClientLogger = std::make_shared<spdlog::logger>("zenclient", FileSink); spdlog::register_logger(ZenClientLogger); ZenClientLogger->set_level(LogLevel); @@ -258,6 +274,7 @@ InitializeLogging(const ZenServerOptions& GlobalOptions) spdlog::set_level(LogLevel); spdlog::flush_on(spdlog::level::err); + spdlog::flush_every(std::chrono::seconds{2}); spdlog::set_formatter(std::make_unique<logging::full_formatter>(GlobalOptions.LogId, std::chrono::system_clock::now())); } |