Menu

Boost 1.65 log formatter warnings - Visual Studio 2017

2017-08-22
2017-08-22
  • John Coffey

    John Coffey - 2017-08-22

    Andrey, I just downloaded the latest release of Boost 1.65 and I noticed that I am getting a warning on the log formatter somewhere in the template expansion. My visual studio warning level is set to 4. I have my compilation set to treat warnings as errors, and although I could work around this by making an exception to ignore warnign level 4244, I would prefer to not have to do this (as was the case in version 1.64). Is there some static_cast I can add to work around this - can you tell me what changed. It appears that the TimeDurationT template parameter passed to decompose_time_of_day contains hours, minutes and seconds getters that return uint32_t values instead of uint64_t. I am building a 64 bit app.

    Thanks in advance

    John

    The way I call the logger is as follows:

    /*static*/
    void
    Logger::init(const std::map<std::string, fs::path>& rLogInfo)
    {
        // Construct the sink for the "event" channel
        for (const auto& rNext : rLogInfo) {
            // empty path=>syslog entry
            if (!rNext.first.empty()) {
                if (!rNext.second.empty()) {
                    static const auto gFormatter = expr::format("%1% [%2%] tid[%3%] %4%")
                        % expr::format_date_time<boost::posix_time::ptime>("TimeStamp", "%H:%M:%S.%f")
                        % logging::trivial::severity
                        % expr::attr<attrs::current_thread_id::value_type>("ThreadID")
                        % expr::smessage;
                    using text_sink = sinks::synchronous_sink<sinks::text_ostream_backend>;
                    auto sink = boost::make_shared<text_sink>();
                    sink->locked_backend()->auto_flush(true);
                    sink->locked_backend()->add_stream(
                        boost::make_shared<std::ofstream>(
                            rNext.second.c_str()));
                    sink->set_formatter(gFormatter);
                    sink->set_filter(expr::attr<std::string>("Channel") == rNext.first);
                    logging::core::get()->add_sink(std::move(sink));
                } else { // syslog entry - time-stamp not required
                    static const auto gFormatter = expr::format("[%1%] tid[%2%] %3%")
                        % logging::trivial::severity
                        % expr::attr<attrs::current_thread_id::value_type>("ThreadID")
                        % expr::smessage;
                    using sink_t = sinks::synchronous_sink<sinks::syslog_backend>;
                    // Create a new backend
    #if defined (_WIN32)
                    auto backend = boost::make_shared<sinks::syslog_backend>(
                        keywords::use_impl = sinks::syslog::udp_socket_based,
                        keywords::facility = sinks::syslog::local7);
                    backend->set_target_address("localhost", 514);
    #else
                    // Create a backend
                    auto backend = boost::make_shared<sinks::syslog_backend>(
                        keywords::use_impl = sinks::syslog::native,
                        keywords::facility = sinks::syslog::local7);
    #endif
                    // We'll have to map our custom levels to the syslog levels
                    sinks::syslog::custom_severity_mapping<trivial::severity_level> mapping("Severity");
                    mapping[trivial::debug] = sinks::syslog::debug;
                    mapping[trivial::info] = sinks::syslog::info;
                    mapping[trivial::warning] = sinks::syslog::warning;
                    mapping[trivial::error] = sinks::syslog::error;
                    mapping[trivial::fatal] = sinks::syslog::critical;
                    backend->set_severity_mapper(mapping);
    
                    // Wrap it into the frontend and register in the core.
                    auto sink = boost::make_shared<sink_t>(backend);
                    sink->set_formatter(gFormatter);
                    sink->set_filter(expr::attr<std::string>("Channel") == rNext.first);
                    logging::core::get()->add_sink(std::move(sink));
                }
            }
        }
        // register common attributes - ThreadID, LineID, TimeStamp etc.
        logging::add_common_attributes();
    }
    

    The error details are as follows:

    3>Logger.cpp
    1>cmdline.vcxproj -> C:\main\dlmu\dlf-0339.1\win32\cmdline\x64\Debug\cmdline.lib
    3>c:\main\extlibs\boost_1_65_0\boost\log\support\date_time.hpp(66): warning C4244: '=': conversion from '__int64' to 'uint32_t', possible loss of data
    3>c:\main\extlibs\boost_1_65_0\boost\log\support\date_time.hpp(109): note: see reference to function template instantiation 'void boost::log::v2s_mt_nt6::expressions::aux::date_time_support::decompose_time_of_day<boost::posix_time::time_duration,boost::posix_time::ptime>(const TimeDurationT &,boost::log::v2s_mt_nt6::aux::decomposed_time_wrapper<boost::posix_time::ptime> &)' being compiled
    3>        with
    3>        [
    3>            TimeDurationT=boost::posix_time::time_duration
    3>        ]
    3>c:\main\extlibs\boost_1_65_0\boost\log\support\date_time.hpp(166): note: see reference to function template instantiation 'void boost::log::v2s_mt_nt6::expressions::aux::date_time_support::decompose_time<boost::posix_time::ptime,boost::posix_time::ptime>(const TimeT &,boost::log::v2s_mt_nt6::aux::decomposed_time_wrapper<boost::posix_time::ptime> &)' being compiled
    3>        with
    3>        [
    3>            TimeT=boost::posix_time::ptime
    3>        ]
    3>c:\main\extlibs\boost_1_65_0\boost\log\support\date_time.hpp(156): note: while compiling class template member function 'void boost::log::v2s_mt_nt6::expressions::aux::date_time_formatter_generator_traits_impl<boost::posix_time::ptime,CharT>::formatter::operator ()(boost::log::v2s_mt_nt6::basic_formatting_ostream<CharT,std::char_traits<char>,std::allocator<char>> &,const boost::posix_time::ptime &) const'
    3>        with
    3>        [
    3>            CharT=char
    3>        ]
    3>c:\main\extlibs\boost_1_65_0\boost\log\detail\light_function.hpp(362): note: see reference to function template instantiation 'void boost::log::v2s_mt_nt6::expressions::aux::date_time_formatter_generator_traits_impl<boost::posix_time::ptime,CharT>::formatter::operator ()(boost::log::v2s_mt_nt6::basic_formatting_ostream<CharT,std::char_traits<char>,std::allocator<char>> &,const boost::posix_time::ptime &) const' being compiled
    3>        with
    3>        [
    3>            CharT=char
    3>        ]
    3>c:\main\extlibs\boost_1_65_0\boost\log\support\date_time.hpp(175): note: see reference to class template instantiation 'boost::log::v2s_mt_nt6::expressions::aux::date_time_formatter_generator_traits_impl<boost::posix_time::ptime,CharT>::formatter' being compiled
    3>        with
    3>        [
    3>            CharT=char
    3>        ]
    3>c:\main\extlibs\boost_1_65_0\boost\log\support\date_time.hpp(174): note: while compiling class template member function 'boost::log::v2s_mt_nt6::aux::light_function<void (boost::log::v2s_mt_nt6::basic_formatting_ostream<char,std::char_traits<char>,std::allocator<char>> &,const boost::posix_time::ptime &)> boost::log::v2s_mt_nt6::expressions::aux::date_time_formatter_generator_traits_impl<boost::posix_time::ptime,CharT>::parse(const std::basic_string<char,std::char_traits<char>,std::allocator<char>> &)'
    3>        with
    3>        [
    3>            CharT=char
    3>        ]
    3>c:\main\extlibs\boost_1_65_0\boost\log\expressions\formatters\date_time.hpp(96): note: see reference to function template instantiation 'boost::log::v2s_mt_nt6::aux::light_function<void (boost::log::v2s_mt_nt6::basic_formatting_ostream<char,std::char_traits<char>,std::allocator<char>> &,const boost::posix_time::ptime &)> boost::log::v2s_mt_nt6::expressions::aux::date_time_formatter_generator_traits_impl<boost::posix_time::ptime,CharT>::parse(const std::basic_string<char,std::char_traits<char>,std::allocator<char>> &)' being compiled
    3>        with
    3>        [
    3>            CharT=char
    3>        ]
    3>c:\main\extlibs\boost_1_65_0\boost\log\support\date_time.hpp(185): note: see reference to class template instantiation 'boost::log::v2s_mt_nt6::expressions::aux::date_time_formatter_generator_traits_impl<boost::posix_time::ptime,CharT>' being compiled
    3>        with
    3>        [
    3>            CharT=char
    3>        ]
    3>c:\main\extlibs\boost_1_65_0\boost\log\expressions\formatters\date_time.hpp(96): note: see reference to class template instantiation 'boost::log::v2s_mt_nt6::expressions::aux::date_time_formatter_generator_traits<boost::posix_time::ptime,char,void>' being compiled
    3>c:\main\extlibs\boost_1_65_0\boost\log\expressions\formatters\date_time.hpp(95): note: while compiling class template member function 'boost::log::v2s_mt_nt6::expressions::format_date_time_terminal<T,FallbackPolicyT,CharT>::format_date_time_terminal(const boost::log::v2s_mt_nt6::attribute_name &,const boost::log::v2s_mt_nt6::fallback_to_none &,const std::basic_string<char,std::char_traits<char>,std::allocator<char>> &)'
    3>        with
    3>        [
    3>            T=boost::posix_time::ptime,
    3>            FallbackPolicyT=boost::log::v2s_mt_nt6::fallback_to_none,
    3>            CharT=char
    3>        ]
    3>c:\main\extlibs\boost_1_65_0\boost\log\expressions\formatters\date_time.hpp(231): note: see reference to function template instantiation 'boost::log::v2s_mt_nt6::expressions::format_date_time_terminal<T,FallbackPolicyT,CharT>::format_date_time_terminal(const boost::log::v2s_mt_nt6::attribute_name &,const boost::log::v2s_mt_nt6::fallback_to_none &,const std::basic_string<char,std::char_traits<char>,std::allocator<char>> &)' being compiled
    3>        with
    3>        [
    3>            T=boost::posix_time::ptime,
    3>            FallbackPolicyT=boost::log::v2s_mt_nt6::fallback_to_none,
    3>            CharT=char
    3>        ]
    3>c:\main\extlibs\boost_1_65_0\boost\mpl\aux_\preprocessed\plain\or.hpp(51): note: see reference to class template instantiation 'boost::log::v2s_mt_nt6::expressions::format_date_time_terminal<T,FallbackPolicyT,CharT>' being compiled
    3>        with
    3>        [
    3>            T=boost::posix_time::ptime,
    3>            FallbackPolicyT=boost::log::v2s_mt_nt6::fallback_to_none,
    3>            CharT=char
    3>        ]
    3>c:\main\extlibs\boost_1_65_0\boost\phoenix\core\actor.hpp(199): note: see reference to class template instantiation 'boost::mpl::or_<boost::phoenix::is_custom_terminal<Expr,void>,boost::mpl::bool_<false>,boost::mpl::false_,boost::mpl::false_,boost::mpl::false_>' being compiled
    3>        with
    3>        [
    3>            Expr=boost::log::v2s_mt_nt6::expressions::format_date_time_terminal<boost::posix_time::ptime,boost::log::v2s_mt_nt6::fallback_to_none,char>
    3>        ]
    3>c:\main\extlibs\boost_1_65_0\boost\log\expressions\formatters\date_time.hpp(154): note: see reference to class template instantiation 'boost::phoenix::actor<boost::log::v2s_mt_nt6::expressions::format_date_time_terminal<T,FallbackPolicyT,CharT>>' being compiled
    3>        with
    3>        [
    3>            T=boost::posix_time::ptime,
    3>            FallbackPolicyT=boost::log::v2s_mt_nt6::fallback_to_none,
    3>            CharT=char
    3>        ]
    3>c:\main\dlmu\dlf-0339.1\src\util\logger.cpp(118): note: see reference to class template instantiation 'boost::log::v2s_mt_nt6::expressions::format_date_time_actor<boost::posix_time::ptime,boost::log::v2s_mt_nt6::fallback_to_none,char,boost::phoenix::actor>' being compiled
    3>c:\main\extlibs\boost_1_65_0\boost\log\support\date_time.hpp(67): warning C4244: '=': conversion from '__int64' to 'uint32_t', possible loss of data
    3>c:\main\extlibs\boost_1_65_0\boost\log\support\date_time.hpp(68): warning C4244: '=': conversion from '__int64' to 'uint32_t', possible loss of data
    3>util.vcxproj -> C:\main\dlmu\dlf-0339.1\win32\util\x64\Debug\util.lib
    3>Done building project "util.vcxproj".
    
     
  • Andrey Semashev

    Andrey Semashev - 2017-08-22

    Is there some static_cast I can add to work around this - can you tell me what changed.

    There was no change in Boost.Log but there might have been a change in Boost.DateTime or some other code or the compiler. Anyway, you will have to either disable the warning or add static_casts to uint32_t in boost/log/support/date_time.hpp in the various decompose_ functions, where there is assignment to decomposed_time_wrapper members.

     

Log in to post a comment.