0

How can I make a deep copy of boost::log::sources::severity_channel_logger_mt object?

I need new logger instance with specified channel and copy of all attributes from source logger.

using namespace boost::log;
using Logger = sources::severity_channel_logger_mt<trivial::severity_level, std::string>;

Logger orig {keywords::channel = "LL"};
orig.add_attribute("tid", attributes::constant<std::string>("TT"));

// This constructor does not affect orig but does not inherit attributes
Logger l0 {orig, keywords::channel = "L0"};
l0.add_attribute("attr", attributes::constant<std::string>("0A"));

// Copy constructor affects orig
Logger l1 {orig};
l1.channel("L1"); // Bad. It right sets l1 channel but affects the orig's channel
l1.add_attribute("attr", attributes::constant<std::string>("1B"));

Boost version is 1.66

sba
  • 199
  • 8
  • 1
    Per https://www.boost.org/doc/libs/1_75_0/libs/log/doc/html/log/detailed/attributes.html all attributes are shallow copied and there is no way to deep copy an attribute. This includes the channel attribute. In 1.76 I made an exception just for the channel attribute, so it should be deep copied by default. But that will not change the behavior for any other attributes. – Andrey Semashev Feb 10 '21 at 11:54
  • This change is a very good option for my case. So I will be able resolve this case in the next way ```Logger nested {orig}; nested.channel("nested");``` It should not affect the orig channel and should inherit all other orig attributes. – sba Feb 10 '21 at 16:35

0 Answers0