I want to build boost::log::formatter conditionally, however, formatter objects do not seem to behave as 'normal values'.
For example:
auto sink = boost::log::add_console_log(std::clog);
auto format =
expr::stream << expr::format_date_time(timestamp, "%Y-%m-%d %H:%M:%S.%f");
boost::log::formatter formatter = format;
if (condition) {
auto t = "msg=" << expr::smessage;
formatter <<= t;
}
sink->set_formatter(formatter);
However, operator<<= (or even operator= for that matter) doesn't seem to modify formatter object which is very surprising for me!
What is the proper way of doing this?