Boost logo

Boost :

Subject: Re: [boost] Boost log issues and workarounds
From: hh h (jupiter.hce_at_[hidden])
Date: 2019-01-18 03:45:04


Hi Andrey,

> Those are just examples in the docs. These particular examples don't
> exist as standalone files. You can find global loggers used in a number
> of other examples in the libs/log/example directory.

The global loggers is working well, but I could not compile the local
log severity, here is the code:

BOOST_LOG_INLINE_GLOBAL_LOGGER_CTOR_ARGS(my_logger,
boost::log::sources::channel_logger_mt< >,
(boost::log::keywords::channel = "general"))

typedef enum {
    INFO,
    DEBUG,
    WARNING,
    ERROR,
    CRITICAL
} ServerityLevel_t;

template<typename CharT, typename TraitsT> std::basic_ostream< CharT,
TraitsT >& operator << (std::basic_ostream< CharT, TraitsT >& strm,
ServerityLevel_t lvl) {
    static const char* const str[] = {
        "INFO",
        "DEBUG",
        "WARNING",
        "ERROR",
        "CRITICAL"
    };
    if (static_cast< std::size_t >(lvl) < (sizeof(str) / sizeof(*str))) {
        strm << str[lvl];
    } else {
        strm << static_cast< int >(lvl);
    }
    return strm;
}

#define LOG(severity) BOOST_LOG_STREAM_WITH_PARAMS((my_logger::get()),
(SetGetAttrib("FileName",
PathToFilename(__FILE__)))(SetGetAttrib("LineNumber", (unsigned
int)__LINE__))(ServerityLevel_t::severity))

/usr/include/boost/log/sources/channel_feature.hpp:171:60: error: no
match for ‘operator[]’ (operand types are ‘const ServerityLevel_t’ and
‘boost::parameter::aux::default_<boost::log::v2_mt_posix::keywords::tag::channel,
const boost::parameter::void_>’)
         return open_record_with_channel_unlocked(args,
args[keywords::channel | parameter::void_()]);

Obviously, you used BOOST_LOG_SEV where I was using
BOOST_LOG_STREAM_WITH_PARAMS, the compiler seems to complain missing
operator[], but I have no clue how to define it.

Thank you.


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk