Boost logo

Boost Users :

From: Allen Cronce (allenslists_at_[hidden])
Date: 2008-08-28 12:27:01


Hi all,

I'm using the boost logging library from the sandbox, in conjunction
with boost 1.35.0. I'm seeing problems building basic sample code
under Windows VS2005 in projects where UNICODE and _UNICODE is defined.

Here's an example line of problematic code:

                g_log_err()->writer().add_formatter( formatter::idx(), "[%] " );

Here's the error generated:

--snip--
1>c:\sources\logutils.cpp(56) : error C2664: 'void
boost
::logging
::writer
::format_write
<
formatter_base
,destination_base
,lock_resource
,apply_format_and_write
,router_type
,formatter_array
,destination_array
>::add_formatter<boost::logging::formatter::idx_t<>>(formatter,const
boost::logging::char_type *)' : cannot convert parameter 2 from 'const
char [5]' to 'const boost::logging::char_type *'
1> with
1> [
1>
formatter_base
=
boost
::logging
::formatter::base<boost::logging::default_,boost::logging::default_>,
1>
destination_base
=
boost
::logging
::destination::base<boost::logging::default_,boost::logging::default_>,
1>
lock_resource=boost::logging::lock_resource_finder::single_thread,
1>
apply_format_and_write
=
boost
::logging
::format_and_write
::simple<boost::logging::optimize::cache_string_one_str<>>,
1>
router_type=boost::logging::msg_route::simple<boost::logging::formatter::base<boost::logging::default_,boost::logging::default_>,boost::logging::destination::base<boost::logging::default_,boost::logging::default_>,boost::logging::lock_resource_finder::single_thread>,
1>
formatter_array
=
boost
::logging
::array
::shared_ptr_holder
<
boost
::logging
::formatter
::base
<
boost
::logging
::default_,boost::logging::default_>,boost::logging::threading::mutex>,
1>
destination_array
=
boost
::logging
::array
::shared_ptr_holder
<
boost
::logging
::destination
::base
<
boost
::logging
::default_,boost::logging::default_>,boost::logging::threading::mutex>,
1> formatter=boost::logging::formatter::idx_t<>
1> ]
1> Types pointed to are unrelated; conversion requires
reinterpret_cast, C-style cast or function-style cast
1>c:\sources\logutils.cpp(58) : error C2440: '<function-style-cast>' :
cannot convert from 'const char [19]' to
'boost::logging::formatter::time'
1> No constructor could take the source type, or constructor
overload resolution was ambiguous
1>c:\sources\logutils.cpp(58) : error C2780: 'void
boost
::logging
::writer
::format_write
<
formatter_base
,destination_base
,lock_resource
,apply_format_and_write
,router_type
,formatter_array,destination_array>::add_formatter(formatter,const
boost::logging::char_type *)' : expects 2 arguments - 1 provided
1> with
1> [
1>
formatter_base
=
boost
::logging
::formatter::base<boost::logging::default_,boost::logging::default_>,
1>
destination_base
=
boost
::logging
::destination::base<boost::logging::default_,boost::logging::default_>,
1>
lock_resource=boost::logging::lock_resource_finder::single_thread,
1>
apply_format_and_write
=
boost
::logging
::format_and_write
::simple<boost::logging::optimize::cache_string_one_str<>>,
1>
router_type=boost::logging::msg_route::simple<boost::logging::formatter::base<boost::logging::default_,boost::logging::default_>,boost::logging::destination::base<boost::logging::default_,boost::logging::default_>,boost::logging::lock_resource_finder::single_thread>,
1>
formatter_array
=
boost
::logging
::array
::shared_ptr_holder
<
boost
::logging
::formatter
::base
<
boost
::logging
::default_,boost::logging::default_>,boost::logging::threading::mutex>,
1>
destination_array
=
boost
::logging
::array
::shared_ptr_holder
<
boost
::logging
::destination
::base
<
boost
::logging
::default_,boost::logging::default_>,boost::logging::threading::mutex>
1> ]
1> c:\sources\thirdpartylibs\installedwin32\individual\boost
\include\boost\logging\detail\format_write_detail.hpp(232) : see
declaration of
'boost
::logging
::writer
::format_write
<
formatter_base
,destination_base
,lock_resource
,apply_format_and_write
,router_type,formatter_array,destination_array>::add_formatter'
1> with
1> [
1>
formatter_base
=
boost
::logging
::formatter::base<boost::logging::default_,boost::logging::default_>,
1>
destination_base
=
boost
::logging
::destination::base<boost::logging::default_,boost::logging::default_>,
1>
lock_resource=boost::logging::lock_resource_finder::single_thread,
1>
apply_format_and_write
=
boost
::logging
::format_and_write
::simple<boost::logging::optimize::cache_string_one_str<>>,
1>
router_type=boost::logging::msg_route::simple<boost::logging::formatter::base<boost::logging::default_,boost::logging::default_>,boost::logging::destination::base<boost::logging::default_,boost::logging::default_>,boost::logging::lock_resource_finder::single_thread>,
1>
formatter_array
=
boost
::logging
::array
::shared_ptr_holder
<
boost
::logging
::formatter
::base
<
boost
::logging
::default_,boost::logging::default_>,boost::logging::threading::mutex>,
1>
destination_array
=
boost
::logging
::array
::shared_ptr_holder
<
boost
::logging
::destination
::base
<
boost
::logging
::default_,boost::logging::default_>,boost::logging::threading::mutex>
1> ]
--snip--

According to the documentation, the library should automatically sense
the UNICODE definition under Windows and do the right thing. But that
doesn't seem to work right.

I played around with trying to get this to work, but found that I had
to always pass non-wide strings to the various interfaces. Ultimately
I gave up and disabled the logging of wide character strings by
defining the following:

#define BOOST_LOG_DONOT_USE_WCHAR_T

For my particular needs, logging 8 bit characters probably makes more
sense anyway. But it's somewhat bothersome that the logging library
did not work out of the box as documented.

Sorry in advance if I missed some other configuration or nuance needed
to get the logging library to work under UNICODE.

Best,

--
Allen Cronce

Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net