From 538d0eedd5d148167ebf9e6f9e9472fa4f9bc808 Mon Sep 17 00:00:00 2001 From: Bill Somerville Date: Fri, 4 Dec 2020 19:01:05 +0000 Subject: [PATCH] Change to wide character logging and handle wide character file paths --- Logger.cpp | 18 +++++++++--------- Logger.hpp | 4 ++-- WSJTXLogging.cpp | 12 ++++++------ 3 files changed, 17 insertions(+), 17 deletions(-) diff --git a/Logger.cpp b/Logger.cpp index 00e5597b1..e92c7aa2a 100644 --- a/Logger.cpp +++ b/Logger.cpp @@ -21,10 +21,10 @@ #include #include #include - -#include +#include #include +namespace fs = boost::filesystem; namespace logging = boost::log; namespace srcs = logging::sources; namespace sinks = logging::sinks; @@ -128,7 +128,7 @@ namespace Logger CommonInitialization ci; } - void init_from_config (std::istream& stream) + void init_from_config (std::wistream& stream) { CommonInitialization ci; try @@ -152,24 +152,24 @@ namespace Logger logging::core::get ()->set_logging_enabled (false); } - void add_datafile_log (std::string const& log_file_name) + void add_datafile_log (std::wstring const& log_file_name) { // Create a text file sink - boost::shared_ptr backend + boost::shared_ptr backend ( - new sinks::text_ostream_backend() + new sinks::wtext_ostream_backend() ); - backend->add_stream (boost::shared_ptr (new std::ofstream (log_file_name))); + backend->add_stream (boost::shared_ptr (new fs::wofstream (log_file_name))); // Flush after each log record backend->auto_flush (true); // Create a sink for the backend - typedef sinks::synchronous_sink sink_t; + typedef sinks::synchronous_sink sink_t; boost::shared_ptr sink (new sink_t (backend)); // The log output formatter - sink->set_formatter (expr::format ("[%1%][%2%] %3%") + sink->set_formatter (expr::format (L"[%1%][%2%] %3%") % expr::attr ("TimeStamp") % logging::trivial::severity % expr::message diff --git a/Logger.hpp b/Logger.hpp index 6e29789e4..5d497943f 100644 --- a/Logger.hpp +++ b/Logger.hpp @@ -21,14 +21,14 @@ namespace Logger void init (); // define logger(s) and sinks from a configuration stream - void init_from_config (std::istream& config_stream); + void init_from_config (std::wistream& config_stream); // disable logging - useful for unit testing etc. void disable (); // add a new file sink for LOG_DATA_* for Severity >= INFO // this file sink will be used alongside any configured above - void add_data_file_log (std::string const& log_file_name); + void add_data_file_log (std::wstring const& log_file_name); } #define LOG_LOG_LOCATION(LOGGER, LEVEL, ARG) \ diff --git a/WSJTXLogging.cpp b/WSJTXLogging.cpp index ffa563b23..e0ba871bd 100644 --- a/WSJTXLogging.cpp +++ b/WSJTXLogging.cpp @@ -93,7 +93,7 @@ namespace << boost::log::add_value ("Line", context.line) << boost::log::add_value ("File", file) << boost::log::add_value ("Function", function) - << msg.toStdString (); + << msg.toStdWString (); } else { @@ -101,7 +101,7 @@ namespace << boost::log::add_value ("Line", context.line) << boost::log::add_value ("File", file) << boost::log::add_value ("Function", function) - << context.category << ": " << msg.toStdString (); + << context.category << ": " << msg.toStdWString (); } if (QtFatalMsg == type) { @@ -155,8 +155,8 @@ WSJTXLogging::WSJTXLogging () pos = match.capturedEnd (0); } new_config += config.mid (pos); - std::stringbuf buffer {new_config.toStdString (), std::ios_base::in}; - std::istream stream {&buffer}; + std::wstringbuf buffer {new_config.toStdWString (), std::ios_base::in}; + std::wistream stream {&buffer}; Logger::init_from_config (stream); LOG_INFO ("Read logging configuration file: " << log_config.fileName ()); } @@ -180,7 +180,7 @@ WSJTXLogging::WSJTXLogging () ( keywords::auto_flush = false #if BOOST_VERSION / 100 >= 1070 - , keywords::file_name = app_data.absoluteFilePath ("wsjtx_syslog.log").toStdString () + , keywords::file_name = app_data.absoluteFilePath ("wsjtx_syslog.log").toStdWString () , keywords::target_file_name = #else , keywords::file_name = @@ -200,7 +200,7 @@ WSJTXLogging::WSJTXLogging () keywords::max_size = 40 * 1024 * 1024 , keywords::min_free_space = 1024 * 1024 * 1024 , keywords::max_files = 12 - , keywords::target = app_data.absoluteFilePath ("logs").toStdString () + , keywords::target = app_data.absoluteFilePath ("logs").toStdWString () ) ); sys_sink->locked_backend ()->scan_for_files ();