mardi 9 février 2021

Deep copy of Boost logger

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"));

Aucun commentaire:

Enregistrer un commentaire