mirror of https://github.com/saitohirga/WSJT-X.git
Change to wide character logging and handle wide character file paths
This commit is contained in:
parent
f3a2c653aa
commit
538d0eedd5
18
Logger.cpp
18
Logger.cpp
|
@ -21,10 +21,10 @@
|
||||||
#include <boost/log/support/date_time.hpp>
|
#include <boost/log/support/date_time.hpp>
|
||||||
#include <boost/shared_ptr.hpp>
|
#include <boost/shared_ptr.hpp>
|
||||||
#include <boost/make_shared.hpp>
|
#include <boost/make_shared.hpp>
|
||||||
|
#include <boost/filesystem/fstream.hpp>
|
||||||
#include <fstream>
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
|
namespace fs = boost::filesystem;
|
||||||
namespace logging = boost::log;
|
namespace logging = boost::log;
|
||||||
namespace srcs = logging::sources;
|
namespace srcs = logging::sources;
|
||||||
namespace sinks = logging::sinks;
|
namespace sinks = logging::sinks;
|
||||||
|
@ -128,7 +128,7 @@ namespace Logger
|
||||||
CommonInitialization ci;
|
CommonInitialization ci;
|
||||||
}
|
}
|
||||||
|
|
||||||
void init_from_config (std::istream& stream)
|
void init_from_config (std::wistream& stream)
|
||||||
{
|
{
|
||||||
CommonInitialization ci;
|
CommonInitialization ci;
|
||||||
try
|
try
|
||||||
|
@ -152,24 +152,24 @@ namespace Logger
|
||||||
logging::core::get ()->set_logging_enabled (false);
|
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
|
// Create a text file sink
|
||||||
boost::shared_ptr<sinks::text_ostream_backend> backend
|
boost::shared_ptr<sinks::wtext_ostream_backend> backend
|
||||||
(
|
(
|
||||||
new sinks::text_ostream_backend()
|
new sinks::wtext_ostream_backend()
|
||||||
);
|
);
|
||||||
backend->add_stream (boost::shared_ptr<std::ostream> (new std::ofstream (log_file_name)));
|
backend->add_stream (boost::shared_ptr<std::wostream> (new fs::wofstream (log_file_name)));
|
||||||
|
|
||||||
// Flush after each log record
|
// Flush after each log record
|
||||||
backend->auto_flush (true);
|
backend->auto_flush (true);
|
||||||
|
|
||||||
// Create a sink for the backend
|
// Create a sink for the backend
|
||||||
typedef sinks::synchronous_sink<sinks::text_ostream_backend> sink_t;
|
typedef sinks::synchronous_sink<sinks::wtext_ostream_backend> sink_t;
|
||||||
boost::shared_ptr<sink_t> sink (new sink_t (backend));
|
boost::shared_ptr<sink_t> sink (new sink_t (backend));
|
||||||
|
|
||||||
// The log output formatter
|
// The log output formatter
|
||||||
sink->set_formatter (expr::format ("[%1%][%2%] %3%")
|
sink->set_formatter (expr::format (L"[%1%][%2%] %3%")
|
||||||
% expr::attr<ptime::ptime> ("TimeStamp")
|
% expr::attr<ptime::ptime> ("TimeStamp")
|
||||||
% logging::trivial::severity
|
% logging::trivial::severity
|
||||||
% expr::message
|
% expr::message
|
||||||
|
|
|
@ -21,14 +21,14 @@ namespace Logger
|
||||||
void init ();
|
void init ();
|
||||||
|
|
||||||
// define logger(s) and sinks from a configuration stream
|
// 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.
|
// disable logging - useful for unit testing etc.
|
||||||
void disable ();
|
void disable ();
|
||||||
|
|
||||||
// add a new file sink for LOG_DATA_* for Severity >= INFO
|
// add a new file sink for LOG_DATA_* for Severity >= INFO
|
||||||
// this file sink will be used alongside any configured above
|
// 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) \
|
#define LOG_LOG_LOCATION(LOGGER, LEVEL, ARG) \
|
||||||
|
|
|
@ -93,7 +93,7 @@ namespace
|
||||||
<< boost::log::add_value ("Line", context.line)
|
<< boost::log::add_value ("Line", context.line)
|
||||||
<< boost::log::add_value ("File", file)
|
<< boost::log::add_value ("File", file)
|
||||||
<< boost::log::add_value ("Function", function)
|
<< boost::log::add_value ("Function", function)
|
||||||
<< msg.toStdString ();
|
<< msg.toStdWString ();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -101,7 +101,7 @@ namespace
|
||||||
<< boost::log::add_value ("Line", context.line)
|
<< boost::log::add_value ("Line", context.line)
|
||||||
<< boost::log::add_value ("File", file)
|
<< boost::log::add_value ("File", file)
|
||||||
<< boost::log::add_value ("Function", function)
|
<< boost::log::add_value ("Function", function)
|
||||||
<< context.category << ": " << msg.toStdString ();
|
<< context.category << ": " << msg.toStdWString ();
|
||||||
}
|
}
|
||||||
if (QtFatalMsg == type)
|
if (QtFatalMsg == type)
|
||||||
{
|
{
|
||||||
|
@ -155,8 +155,8 @@ WSJTXLogging::WSJTXLogging ()
|
||||||
pos = match.capturedEnd (0);
|
pos = match.capturedEnd (0);
|
||||||
}
|
}
|
||||||
new_config += config.mid (pos);
|
new_config += config.mid (pos);
|
||||||
std::stringbuf buffer {new_config.toStdString (), std::ios_base::in};
|
std::wstringbuf buffer {new_config.toStdWString (), std::ios_base::in};
|
||||||
std::istream stream {&buffer};
|
std::wistream stream {&buffer};
|
||||||
Logger::init_from_config (stream);
|
Logger::init_from_config (stream);
|
||||||
LOG_INFO ("Read logging configuration file: " << log_config.fileName ());
|
LOG_INFO ("Read logging configuration file: " << log_config.fileName ());
|
||||||
}
|
}
|
||||||
|
@ -180,7 +180,7 @@ WSJTXLogging::WSJTXLogging ()
|
||||||
(
|
(
|
||||||
keywords::auto_flush = false
|
keywords::auto_flush = false
|
||||||
#if BOOST_VERSION / 100 >= 1070
|
#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 =
|
, keywords::target_file_name =
|
||||||
#else
|
#else
|
||||||
, keywords::file_name =
|
, keywords::file_name =
|
||||||
|
@ -200,7 +200,7 @@ WSJTXLogging::WSJTXLogging ()
|
||||||
keywords::max_size = 40 * 1024 * 1024
|
keywords::max_size = 40 * 1024 * 1024
|
||||||
, keywords::min_free_space = 1024 * 1024 * 1024
|
, keywords::min_free_space = 1024 * 1024 * 1024
|
||||||
, keywords::max_files = 12
|
, 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 ();
|
sys_sink->locked_backend ()->scan_for_files ();
|
||||||
|
|
Loading…
Reference in New Issue