-1

Following the question asked here Boost.Log, using custom attributes in filename or target value of configuration file, I tried to develop the proposed solution but I encounter a build issue on Windows due to wchar_t vs char while trying to set the name of the files.

Error C2664 'boost::log::v2s_mt_nt6::basic_formatter<char>::result_type boost::log::v2s_mt_nt6::basic_formatter<char>::operator ()(const boost::log::v2s_mt_nt6::record_view &,boost::log::v2s_mt_nt6::basic_formatting_ostream<char,std::char_traits<char>,std::allocator<char>> &) const': cannot convert argument 2 from 'boost::log::v2s_mt_nt6::sinks::file::file_name_composer_adapter<boost::log::v2s_mt_nt6::basic_formatter<char>>::stream_type' to 'boost::log::v2s_mt_nt6::basic_formatting_ostream<char,std::char_traits<char>,std::allocator<char>> &'

file: boost\log\sinks\text_multifile_backend.hpp 107
stream_type being ostream of wchar_t due to Windows
if (boost::optional< std::string > param = settings["FileName"]) {
auto fmt = logging::parse_formatter((*param));
auto composer = sinks::file::as_file_name_composer(fmt);
backend->set_file_name_composer(composer);
}

How can I make parse_formatter works with wchar_t?

I also tried to use wchar_t as type of the sink_factory + std::wstring but it doesn't build either

Error C2664 'boost::log::v2s_mt_nt6::basic_formatter<wchar_t>::result_type boost::log::v2s_mt_nt6::basic_formatter<wchar_t>::operator ()(const boost::log::v2s_mt_nt6::record_view &,boost::log::v2s_mt_nt6::basic_formatting_ostream<wchar_t,std::char_traits<wchar_t>,std::allocator<wchar_t>> &) const': cannot convert argument 2 from 'boost::log::v2s_mt_nt6::expressions::aux::stream_ref<boost::log::v2s_mt_nt6::basic_formatting_ostream<char,std::char_traits<char>,std::allocator<char>>>' to 'boost::log::v2s_mt_nt6::basic_formatting_ostream<wchar_t,std::char_traits<wchar_t>,std::allocator<wchar_t>> &'

file: boost\log\detail\light_function.hpp 362

supplying 'std::locale("en_US.UTF-8")' to the composer doesn't change anything as it's runtime

same remark for "expr::stream << expr::format(*param)" as formatter

I'm using boost_1_70_0

Do you know any solution?

Thanks!

Joel
  • 669
  • 7
  • 25

1 Answers1

0

parse_formatter returns basic_formatter<CharT>, where CharT is the character type deduced from the input argument. Thus, you will need to pass std::wstring in order to get wformatter which you can use with as_file_name_composer.

In order to get std::wstring parameter values from settings you will have to use wsettings, which you can obtain from parse_settings if you pass a std::wistream as input.

Andrey Semashev
  • 10,046
  • 1
  • 17
  • 27