From cc8c720f17d2b1f69cfaebc74fa4a951ad2a842e Mon Sep 17 00:00:00 2001 From: NotAdam Date: Thu, 25 Oct 2018 15:39:36 +1100 Subject: [PATCH] fix file extension for log files & always flush log on critical messages --- src/common/Logging/Logger.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/common/Logging/Logger.cpp b/src/common/Logging/Logger.cpp index 213a6ea8..3261a4e7 100644 --- a/src/common/Logging/Logger.cpp +++ b/src/common/Logging/Logger.cpp @@ -30,10 +30,15 @@ void Logger::init() std::vector< spdlog::sink_ptr > sinks; sinks.push_back( std::make_shared< spdlog::sinks::stdout_color_sink_mt >() ); - sinks.push_back( std::make_shared< spdlog::sinks::daily_file_sink_mt >( m_logFile, 0, 0 ) ); + sinks.push_back( std::make_shared< spdlog::sinks::daily_file_sink_mt >( m_logFile + ".log", 0, 0 ) ); m_logger = std::make_shared< spdlog::logger >( "logger", std::begin( sinks ), std::end( sinks ) ); + // always flush the log on criticial messages, otherwise it's done by libc + // see: https://github.com/gabime/spdlog/wiki/7.-Flush-policy + // nb: if the server crashes, log data can be missing from the file unless something logs critical just before it does + m_logger->flush_on( spdlog::level::critical ); + //spdlog::set_pattern( "[%H:%M:%S] [%l] %v" ); }