Boost logo

Boost Users :

Subject: Re: [Boost-users] Initializing of Boost.Log
From: Igor Mironchik (igor.mironchik_at_[hidden])
Date: 2015-01-11 02:48:39


Hi,

I modified a little the code and now I have compiler error:

#include <boost/log/trivial.hpp>
#include <boost/log/sinks.hpp>
#include <boost/log/expressions.hpp>
#include <boost/log/utility/setup/common_attributes.hpp>
#include <boost/log/utility/setup/file.hpp>

void init()
{
     boost::log::add_file_log
     (
         boost::log::keywords::file_name = "sample_%Y%m%d.log",
         boost::log::keywords::auto_flush = true,
         boost::log::keywords::open_mode = ( std::ios::out | std::ios::app
),
         boost::log::keywords::time_based_rotation =
boost::log::sinks::file::rotation_at_time_point( 0, 0, 0 ),
         boost::log::keywords::format =
         (
             boost::log::expressions::stream
                 << boost::log::expressions::format_date_time<
boost::posix_time::ptime >( "TimeStamp", "[%H:%M:%S]" )
                 << " [" << boost::log::trivial::severity
                 << "] : " << boost::log::expressions::smessage
         )
     );

     boost::log::add_common_attributes();
}

int main(int, char*[])
{
     init();

     BOOST_LOG_TRIVIAL( trace ) << "A trace severity message";
     BOOST_LOG_TRIVIAL( debug ) << "A debug severity message";
     BOOST_LOG_TRIVIAL( info ) << "An informational severity message";
     BOOST_LOG_TRIVIAL( warning ) << "A warning severity message";
     BOOST_LOG_TRIVIAL( error ) << "An error severity message";
     BOOST_LOG_TRIVIAL( fatal ) << "A fatal severity message";

     return 0;
}

What produces the next errors:

C:\Thirdparty\include\boost/log/expressions/formatters/date_time.hpp(94) :
error
  C2027: use of undefined type
'boost::log::v2s_mt_nt5::expressions::aux::date_ti
me_formatter_generator_traits<boost::posix_time::ptime,char,void>'
         C:\Thirdparty\include\boost/log/expressions/formatters/date_time.hpp(93)
  : while compiling class template member function
'boost::log::v2s_mt_nt5::expre
ssions::format_date_time_terminal<T,FallbackPolicyT,CharT>::format_date_time_ter
minal(const boost::log::v2s_mt_nt5::attribute_name &,const
boost::log::v2s_mt_nt
5::fallback_to_none &,const
std::basic_string<char,std::char_traits<char>,std::a
llocator<char>> &)'
         with
         [
             T=boost::posix_time::ptime
, FallbackPolicyT=boost::log::v2s_mt_nt5::fallback_to_none
, CharT=char
         ]
         C:\Thirdparty\include\boost/log/expressions/formatters/date_time.hpp(229
) : see reference to function template instantiation
'boost::log::v2s_mt_nt5::ex
pressions::format_date_time_terminal<T,FallbackPolicyT,CharT>::format_date_time_
terminal(const boost::log::v2s_mt_nt5::attribute_name &,const
boost::log::v2s_mt
_nt5::fallback_to_none &,const
std::basic_string<char,std::char_traits<char>,std
::allocator<char>> &)' being compiled
         with
         [
             T=boost::posix_time::ptime
, FallbackPolicyT=boost::log::v2s_mt_nt5::fallback_to_none
, CharT=char
         ]
         C:\Thirdparty\include\boost/mpl/aux_/preprocessed/plain/or.hpp(51)
: see
  reference to class template instantiation
'boost::log::v2s_mt_nt5::expressions:
:format_date_time_terminal<T,FallbackPolicyT,CharT>' being compiled
         with
         [
             T=boost::posix_time::ptime
, FallbackPolicyT=boost::log::v2s_mt_nt5::fallback_to_none
, CharT=char
         ]
         C:\Thirdparty\include\boost/phoenix/core/actor.hpp(192) : see
reference
to class template instantiation
'boost::mpl::or_<boost::phoenix::is_custom_termi
nal<Expr,void>,boost::mpl::bool_<false>,boost::mpl::false_,boost::mpl::false_,bo
ost::mpl::false_>' being compiled
         with
         [
             Expr=boost::log::v2s_mt_nt5::expressions::format_date_time_terminal<
boost::posix_time::ptime,boost::log::v2s_mt_nt5::fallback_to_none,char>
         ]
         C:\Thirdparty\include\boost/log/expressions/formatters/date_time.hpp(152
) : see reference to class template instantiation
'boost::phoenix::actor<boost::
log::v2s_mt_nt5::expressions::format_date_time_terminal<T,FallbackPolicyT,CharT>
> ' being compiled
         with
         [
             T=boost::posix_time::ptime
, FallbackPolicyT=boost::log::v2s_mt_nt5::fallback_to_none
, CharT=char
         ]
         .\main.cpp(20) : see reference to class template instantiation
'boost::l
og::v2s_mt_nt5::expressions::format_date_time_actor<boost::posix_time::ptime,boo
st::log::v2s_mt_nt5::fallback_to_none,char,boost::phoenix::actor>' being
compile
d
C:\Thirdparty\include\boost/log/expressions/formatters/date_time.hpp(94) :
error
  C3861: 'parse': identifier not found
NMAKE : fatal error U1077: '"c:\Program Files (x86)\Microsoft Visual
Studio 12.0
\VC\bin\cl.EXE"' : return code '0x2'
Stop.
NMAKE : fatal error U1077: '"c:\Program Files (x86)\Microsoft Visual
Studio 12.0
\VC\bin\nmake.exe"' : return code '0x2'
Stop.
On Sun, 11 Jan 2015 09:55:13 +0300, Igor Mironchik
<igor.mironchik_at_[hidden]> wrote:

> Hi guys,
>
> I want to initialize simple log. I do the next:
>
>
> #include <boost/log/utility/setup/file.hpp>
> #include <boost/log/trivial.hpp>
> #include <boost/log/utility/setup/common_attributes.hpp>
>
> void init()
> {
> boost::log::add_file_log
> (
> boost::log::keywords::file_name = "sample_%Y%m%d.log",
> boost::log::keywords::auto_flush = true,
> boost::log::keywords::open_mode = (std::ios::out |
> std::ios::app),
> boost::log::keywords::format = "[%TimeStamp%] [%Severity%]:
> %Message%"
> );
>
> boost::log::add_common_attributes();
> }
>
> int main(int, char*[])
> {
> init();
>
> BOOST_LOG_TRIVIAL( trace ) << "A trace severity message";
> BOOST_LOG_TRIVIAL( debug ) << "A debug severity message";
> BOOST_LOG_TRIVIAL( info ) << "An informational severity message";
> BOOST_LOG_TRIVIAL( warning ) << "A warning severity message";
> BOOST_LOG_TRIVIAL( error ) << "An error severity message";
> BOOST_LOG_TRIVIAL( fatal ) << "A fatal severity message";
>
> return 0;
> }
>
> But in log I receive:
>
> [2015-Jan-11 09:51:04.082221] []: A trace severity message
> [2015-Jan-11 09:51:04.082221] []: A debug severity message
> [2015-Jan-11 09:51:04.082221] []: An informational severity message
> [2015-Jan-11 09:51:04.092221] []: A warning severity message
> [2015-Jan-11 09:51:04.092221] []: An error severity message
> [2015-Jan-11 09:51:04.092221] []: A fatal severity message
>
>
> And my question is how to initialize logging to write severity level in
> messages?
>
> What do I miss?
>
> Thank you.
>

-- 
Best Regards,
Igor Mironchik.

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