billy.donahue 2019/10/01 19:39:57
|
Even here for this short-term code I really strongly dislike the copy-paste.
|
I have to eyeball every line of doLogImpl function and doLogRecordImpl to see
|
how they differ.
|
|
There are two big functions that are mostly the same.
|
Inside each are two big statements that are mostly the same too.
|
Would something like this make sense to orthogonalize this stuff?
|
|
template <typename K, typename V>
|
void insertRecord(LogRecord& record, K&& key, V&& obj) {
|
auto impl = boost::intrusive_ptr(
|
new boost::log::attributes::attribute_value_impl<V>(obj));
|
record.attribute_values().insert(
|
key,
|
boost::log::attribute_value(std::move(impl)));
|
}
|
|
void doLogImpl(LogSeverity const& severity,
|
LogOptions const& options,
|
StringData stable_id,
|
StringData message,
|
AttributeArgumentSet const& attrs) {
|
auto& source = options.domain().impl().source();
|
auto record = source.open_record(
|
severity, options.component(),
|
options.tags(), stable_id);
|
doLogRecordImpl(std::move(record), options.domain(), message, attrs);
|
}
|
|
void doLogRecordImpl(LogRecord&& record,
|
LogDomain& domain,
|
StringData message,
|
AttributeArgumentSet const& attrs) {
|
auto& source = domain.impl().source();
|
auto record = std::move(record.impl()->_record);
|
if (record) {
|
insertRecord(record, attributes::message(), message);
|
insertRecord(record, attributes::attributes(), attrs);
|
source.push_record(std::move(record));
|
}
|
}
|